|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.PropertyFilter
public class PropertyFilter
Used to store filter settings in the current context. A filter is
a simple expression of the form: property operator value
,
ie. name = 'Nicklas'
or spots > 10000
.
SessionControl.getCurrentContext(Item)
,
ItemContext
Field Summary | |
---|---|
private Pattern |
ENTITY_COLLECTION
|
static int |
MAX_VALUE_LENGTH
The maximum allowed length of a filter value. |
private Operator |
operator
|
private String |
property
|
private boolean |
temporary
|
static boolean |
TEMPORARY
Flag to use for temporary filters. |
private Unit |
unit
|
private String |
value
|
private static String |
value_separator
The string/characters used as a separator in a string with more then one filter values. |
private Type |
valueType
|
Constructor Summary | |
---|---|
PropertyFilter(String property)
Create a new filter for a property. |
|
PropertyFilter(String property,
Operator operator,
String value,
Type valueType)
Create a new filter for a property. |
|
PropertyFilter(String property,
Operator operator,
String value,
Type valueType,
boolean temporary)
Create a new filter for a property. |
|
PropertyFilter(String property,
PropertyFilterData filter)
Create a new filter from a loaded database object. |
Method Summary | |
---|---|
private Double |
convertValueToUnit(org.hibernate.Session session,
String value,
String unitSymbol,
Unit convertTo)
Converts a string to a numeric value with the correct unit. |
(package private) PropertyFilterData |
getData()
Create a new database filter object from this filter. |
Restriction |
getDynamicRestriction(DbControl dc)
|
Operator |
getOperator()
Get the operator to use in the filter. |
String |
getProperty()
Get the name of the property this filter is used on. |
Restriction |
getRestriction()
Deprecated. Use getRestriction(DbControl, EntityQuery) instead |
Restriction |
getRestriction(DbControl dc)
Deprecated. Use getRestriction(DbControl, EntityQuery) instead |
Restriction |
getRestriction(DbControl dc,
EntityQuery query)
Create a restriction from the filter. |
String |
getValue()
Get the value to use in the filter. |
Object |
getValueAsObject()
Get the value as an object of the correct type. |
Object |
getValueAsObject(Unit unit,
boolean asDouble)
Get the value as an object of the proper type converted to the specified unit. |
List<Object> |
getValuesAsObjects()
Splits the value string at each "|" and creates a list with objects from the substrings that were found. |
List<Object> |
getValuesAsObjects(Unit unit,
boolean asDouble)
Same as getValueAsObject(Unit, boolean) but the filter string
is first split at each "|". |
String |
getValueSeparator()
|
Type |
getValueType()
Get the type of the property. |
boolean |
isTemporary()
Is this filter a temporary filter or not. |
void |
setOperator(Operator operator)
Set the operator to use in the filter. |
void |
setTemporary(boolean temporary)
Set or clear a flag indicating that this filter is temporary filter. |
void |
setUnit(Unit unit)
Sets the unit the values for the property are stored in the database. |
void |
setValue(String value)
Set the value to use in the filter. |
void |
setValueType(Type valueType)
Set the type of the property. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAX_VALUE_LENGTH
public static final boolean TEMPORARY
private static final String value_separator
private final Pattern ENTITY_COLLECTION
private final String property
private Type valueType
private Operator operator
private String value
private Unit unit
private boolean temporary
Constructor Detail |
---|
public PropertyFilter(String property)
property
- The name of the propertypublic PropertyFilter(String property, Operator operator, String value, Type valueType)
property
- The name of the propertyoperator
- The operator to usevalue
- The value to check againstvalueType
- The type of the valuepublic PropertyFilter(String property, Operator operator, String value, Type valueType, boolean temporary)
property
- The name of the propertyoperator
- The operator to usevalue
- The value to check againstvalueType
- The type of the valuetemporary
- A flag indicating if the filter should be temporary or notPropertyFilter(String property, PropertyFilterData filter)
Method Detail |
---|
PropertyFilterData getData()
public String toString()
toString
in class Object
public void setTemporary(boolean temporary)
public boolean isTemporary()
public String getProperty()
public Type getValueType()
public void setValueType(Type valueType)
valueType
- The typepublic Operator getOperator()
public void setOperator(Operator operator)
public void setUnit(Unit unit)
unit
- The unit, or null to remove the unit from the filterpublic String getValue()
public void setValue(String value)
value
- The value as a stringpublic Object getValueAsObject()
Note! The returned value is cast to the class supported by
the getValueType()
. Beware of this when the
filter has an integer type and a unit with low precision.
For example, if the value is '125min' and the unit is
'hour' this method returns the integer 2. To avoid this
use getValueAsObject(Unit, boolean)
with
asDouble=true instead.
InvalidDataException
- If the string value can't be parsedpublic Object getValueAsObject(Unit unit, boolean asDouble)
If the asDouble parameter is true, the value is returned as a
double, otherwise it is cast to the
proper class as specified by the getValueType()
.
Note! The above only applies for numerical properties that
has a unit. If not, the value is simply parsed with
Type.parseString(String)
.
unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE
to let the getValueType()
decide
public List<Object> getValuesAsObjects()
InvalidDataException
- If any of the string values can't be parsed.public List<Object> getValuesAsObjects(Unit unit, boolean asDouble)
getValueAsObject(Unit, boolean)
but the filter string
is first split at each "|". Each individual string may or may not specify
a unit. If a unit is specified for some parts but not for all, the nearest
following unit is used. For example, the string '300g|5|10kg' is the same as
'300g|5kg|10kg'.'
unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE
to let the getValueType()
decide
private Double convertValueToUnit(org.hibernate.Session session, String value, String unitSymbol, Unit convertTo)
session
- Hibernate session used to lookup unitsvalue
- The string value which should be parsable with
Double.parseDouble(String)
unitSymbol
- The unit of the string valueconvertTo
- The unit to convert the value to
public Restriction getRestriction()
getRestriction(DbControl, EntityQuery)
instead
public Restriction getRestriction(DbControl dc)
getRestriction(DbControl, EntityQuery)
instead
public Restriction getRestriction(DbControl dc, EntityQuery query)
If the property starts with a $ it is interpreted as a alias.property
value, ignoring the root alias of the query. The alias is removed from the
property before proceeding.
If the property starts with a # or ## it is a filter on annotations. The rest of
the property is the ID of the annotation type, and we use a
AnnotationSimpleRestriction
object for the restriction. If there
is only one # in the prefix only direct annotations are searched, if there
are two ##, inherited annotations are also searched.
If the property starts with a £, the rest of the property is the path that
joins the ReporterData.getReporterListScores()
collection. The filter
value is the ID of the reporter list.
If the property starts with a @ the property is a collection of values and we always use an IN restriction, ignoring the specified operator.
If the property starts with & it is a collection of entities. The property must end with a property name from the entity in the collection within paranthesis. Eg. &experiments(name). The filter is applied as a subquery.
If the property starts with ! it is another special filter. There is currently one such filter (since BASE 2.15): !sharedTo.name, which is used to filter shareable items by the name of users/groups/projects it has been shared to. The 'name' part can be replaced with any other property that is common for users, groups and projects (eg. description or id).
The property may also start with $@.
public Restriction getDynamicRestriction(DbControl dc)
public String getValueSeparator()
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |