2.8.3: 2008-10-15

net.sf.basedb.core
Class PropertyFilter

java.lang.Object
  extended by net.sf.basedb.core.PropertyFilter

public class PropertyFilter
extends Object

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.

Version:
2.0
Author:
Nicklas
See Also:
SessionControl.getCurrentContext(Item), ItemContext
Last modified
$Date: 2008-09-05 17:16:27 +0200 (Fri, 05 Sep 2008) $

Field Summary
static int MAX_VALUE_LENGTH
          The maximum allowed length of a filter value.
private  Operator operator
           
private  String property
           
private  String value
           
private  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, PropertyFilterData filter)
          Create a new filter from a loaded database object.
 
Method Summary
(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) instead
 Restriction getRestriction(DbControl dc)
          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.
 List<Object> getValuesAsObjects()
          Splits the value string at each "|" and creates a list with objects from the substrings that were found.
 String getValueSeparator()
           
 Type getValueType()
          Get the type of the property.
 void setOperator(Operator operator)
          Set the operator to use in the filter.
 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

MAX_VALUE_LENGTH

public static final int MAX_VALUE_LENGTH
The maximum allowed length of a filter value.

Since:
2.6.2
See Also:
Constant Field Values

value_separator

private final String value_separator
The string/characters used as a separator in a string with more then one filter values.

See Also:
Constant Field Values

property

private final String property

valueType

private Type valueType

operator

private Operator operator

value

private String value
Constructor Detail

PropertyFilter

public PropertyFilter(String property)
Create a new filter for a property.

Parameters:
property - The name of the property

PropertyFilter

public PropertyFilter(String property,
                      Operator operator,
                      String value,
                      Type valueType)
Create a new filter for a property.

Parameters:
property - The name of the property
operator - The operator to use
value - The value to check against
valueType - The type of the value

PropertyFilter

PropertyFilter(String property,
               PropertyFilterData filter)
Create a new filter from a loaded database object.

Method Detail

getData

PropertyFilterData getData()
Create a new database filter object from this filter.


toString

public String toString()
Overrides:
toString in class Object

getProperty

public String getProperty()
Get the name of the property this filter is used on.


getValueType

public Type getValueType()
Get the type of the property.


setValueType

public void setValueType(Type valueType)
Set the type of the property.

Parameters:
valueType - The type

getOperator

public Operator getOperator()
Get the operator to use in the filter.


setOperator

public void setOperator(Operator operator)
Set the operator to use in the filter.


getValue

public String getValue()
Get the value to use in the filter.

Returns:
The value as a string

setValue

public void setValue(String value)
Set the value to use in the filter.

Parameters:
value - The value as a string

getValueAsObject

public Object getValueAsObject()
Get the value as an object of the correct type. The Type.parseString(String) is used to convert the value.

Returns:
The value as an object
Throws:
InvalidDataException - If the string value can't be parsed

getValuesAsObjects

public List<Object> getValuesAsObjects()
Splits the value string at each "|" and creates a list with objects from the substrings that were found.

Returns:
A list with objects, or null if splitting string of values returns null.
Throws:
InvalidDataException - If any of the string values can't be parsed.
Since:
2.5

getRestriction

public Restriction getRestriction()
Deprecated. Use getRestriction(DbControl) instead

This method will fail if used to filter on reporter lists.


getRestriction

public Restriction getRestriction(DbControl dc)
Create a restriction from the filter. There are a few special cases:

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.

The property may also start with $@.

Returns:
The restriction
Since:
2.8

getDynamicRestriction

public Restriction getDynamicRestriction(DbControl dc)

getValueSeparator

public String getValueSeparator()

2.8.3: 2008-10-15