Class Filter
- Object
-
- Filter
-
- All Implemented Interfaces:
Serializable
public class Filter extends Object implements Serializable
A
Filteris used by theSearchclass to specify a restriction on what results should be returned in the search. For example, if a filterFilter.equal("name","Paul")were added to the search, only objects with the property "name" equal to the string "Paul" would be returned.Nested properties can also be specified, for example
Filter.greaterThan("employee.age",65).- Author:
- dwolverton
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intOP_ALLstatic intOP_ANDstatic intOP_CUSTOMstatic intOP_EMPTYstatic intOP_EQUALstatic intOP_GREATER_OR_EQUALstatic intOP_GREATER_THANstatic intOP_ILIKEstatic intOP_INstatic intOP_LESS_OR_EQUALstatic intOP_LESS_THANstatic intOP_LIKEstatic intOP_NONEstatic intOP_NOTstatic intOP_NOT_EMPTYstatic intOP_NOT_EQUALstatic intOP_NOT_INstatic intOP_NOT_NULLstatic intOP_NULLstatic intOP_ORstatic intOP_SOMEprotected intoperatorThe type of comparison to do between the property and the value.protected StringpropertyThe name of the property to filter on.static StringROOT_ENTITYProperty string representing the root entity of the search.protected ObjectvalueThe value to compare the property with.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Filter filter)Used with OP_OR and OP_AND filters.static Filterall(String property, Filter filter)Create a new Filter using the ALL operator.static Filterand(Filter... filters)Create a new Filter using the AND operator.static Filtercustom(String expression)Create a new Filter using a custom JPQL/HQL expression.static Filtercustom(String expression, Object... values)Create a new Filter using a custom JPQL/HQL expression.static Filtercustom(String expression, Collection<?> values)Create a new Filter using a custom JPQL/HQL expression.static Filterequal(String property, Object value)Create a new Filter using the == operator.booleanequals(Object obj)intgetOperator()StringgetProperty()ObjectgetValue()Collection<?>getValuesAsCollection()Returns the value as a Collection, converting if necessary.List<?>getValuesAsList()Returns the value as a List, converting if necessary.static FiltergreaterOrEqual(String property, Object value)Create a new Filter using the >= operator.static FiltergreaterThan(String property, Object value)Create a new Filter using the > operator.inthashCode()static Filterilike(String property, String value)Create a new Filter using the ILIKE operator.static Filterin(String property, Object... value)Create a new Filter using the IN operator.static Filterin(String property, Collection<?> value)Create a new Filter using the IN operator.static FilterisEmpty(String property)Create a new Filter using the IS EMPTY operator.static booleanisFilter(Map<String,?> filter)static FilterisNotEmpty(String property)Create a new Filter using the IS NOT EMPTY operator.static FilterisNotNull(String property)Create a new Filter using the IS NOT NULL operator.static FilterisNull(String property)Create a new Filter using the IS NULL operator.booleanisTakesListOfSubFilters()booleanisTakesListOfValues()booleanisTakesNoProperty()booleanisTakesNoValue()booleanisTakesSingleSubFilter()booleanisTakesSingleValue()static FilterlessOrEqual(String property, Object value)Create a new Filter using the <= operator.static FilterlessThan(String property, Object value)Create a new Filter using the < operator.static Filterlike(String property, String value)Create a new Filter using the LIKE operator.booleanmatches(MatcherContext context)static Filternone(String property, Filter filter)Create a new Filter using the NONE operator.static Filternot(Filter filter)Create a new Filter using the NOT operator.static FilternotEqual(String property, Object value)Create a new Filter using the != operator.static FilternotIn(String property, Object... value)Create a new Filter using the NOT IN operator.static FilternotIn(String property, Collection<?> value)Create a new Filter using the NOT IN operator.static Filteror(Filter... filters)Create a new Filter using the OR operator.static FilterreconstructFromMap(Map<String,?> filterAsMap)voidremove(Filter filter)Used with OP_OR and OP_AND filters.voidsetOperator(int operator)voidsetProperty(String property)voidsetValue(Object value)static Filtersome(String property, Filter filter)Create a new Filter using the SOME operator.StringtoQueryString()StringtoString()
-
-
-
Field Detail
-
ROOT_ENTITY
public static final String ROOT_ENTITY
Property string representing the root entity of the search. This is just the empty string ("").- See Also:
- Constant Field Values
-
property
protected String property
The name of the property to filter on. It may be nested. Examples:"name", "dateOfBirth", "employee.age", "employee.spouse.job.title"
-
value
protected Object value
The value to compare the property with. Should be of a compatible type with the property. Examples:"Fred", new Date(), 45
-
operator
protected int operator
The type of comparison to do between the property and the value. The options are limited to the integer constants on this class:OP_EQAUL, OP_NOT_EQUAL, OP_LESS_THAN, OP_GREATER_THAN, LESS_OR_EQUAL, OP_GREATER_OR_EQUAL, OP_IN, OP_NOT_IN, OP_LIKE, OP_ILIKE, OP_NULL, OP_NOT_NULL, OP_EMPTY, OP_NOT_EMPTY, OP_SOME, OP_ALL, OP_NONE, OP_AND, OP_OR, OP_NOT.
-
OP_EQUAL
public static final int OP_EQUAL
- See Also:
- Constant Field Values
-
OP_NOT_EQUAL
public static final int OP_NOT_EQUAL
- See Also:
- Constant Field Values
-
OP_LESS_THAN
public static final int OP_LESS_THAN
- See Also:
- Constant Field Values
-
OP_GREATER_THAN
public static final int OP_GREATER_THAN
- See Also:
- Constant Field Values
-
OP_LESS_OR_EQUAL
public static final int OP_LESS_OR_EQUAL
- See Also:
- Constant Field Values
-
OP_GREATER_OR_EQUAL
public static final int OP_GREATER_OR_EQUAL
- See Also:
- Constant Field Values
-
OP_LIKE
public static final int OP_LIKE
- See Also:
- Constant Field Values
-
OP_ILIKE
public static final int OP_ILIKE
- See Also:
- Constant Field Values
-
OP_IN
public static final int OP_IN
- See Also:
- Constant Field Values
-
OP_NOT_IN
public static final int OP_NOT_IN
- See Also:
- Constant Field Values
-
OP_NULL
public static final int OP_NULL
- See Also:
- Constant Field Values
-
OP_NOT_NULL
public static final int OP_NOT_NULL
- See Also:
- Constant Field Values
-
OP_EMPTY
public static final int OP_EMPTY
- See Also:
- Constant Field Values
-
OP_NOT_EMPTY
public static final int OP_NOT_EMPTY
- See Also:
- Constant Field Values
-
OP_AND
public static final int OP_AND
- See Also:
- Constant Field Values
-
OP_OR
public static final int OP_OR
- See Also:
- Constant Field Values
-
OP_NOT
public static final int OP_NOT
- See Also:
- Constant Field Values
-
OP_SOME
public static final int OP_SOME
- See Also:
- Constant Field Values
-
OP_ALL
public static final int OP_ALL
- See Also:
- Constant Field Values
-
OP_NONE
public static final int OP_NONE
- See Also:
- Constant Field Values
-
OP_CUSTOM
public static final int OP_CUSTOM
- See Also:
- Constant Field Values
-
-
Method Detail
-
equal
public static Filter equal(String property, Object value)
Create a new Filter using the == operator.
-
lessThan
public static Filter lessThan(String property, Object value)
Create a new Filter using the < operator.
-
greaterThan
public static Filter greaterThan(String property, Object value)
Create a new Filter using the > operator.
-
lessOrEqual
public static Filter lessOrEqual(String property, Object value)
Create a new Filter using the <= operator.
-
greaterOrEqual
public static Filter greaterOrEqual(String property, Object value)
Create a new Filter using the >= operator.
-
in
public static Filter in(String property, Collection<?> value)
Create a new Filter using the IN operator.This takes a variable number of parameters. Any number of values can be specified.
-
in
public static Filter in(String property, Object... value)
Create a new Filter using the IN operator.This takes a variable number of parameters. Any number of values can be specified.
-
notIn
public static Filter notIn(String property, Collection<?> value)
Create a new Filter using the NOT IN operator.This takes a variable number of parameters. Any number of values can be specified.
-
notIn
public static Filter notIn(String property, Object... value)
Create a new Filter using the NOT IN operator.This takes a variable number of parameters. Any number of values can be specified.
-
like
public static Filter like(String property, String value)
Create a new Filter using the LIKE operator.
-
ilike
public static Filter ilike(String property, String value)
Create a new Filter using the ILIKE operator.
-
notEqual
public static Filter notEqual(String property, Object value)
Create a new Filter using the != operator.
-
isNull
public static Filter isNull(String property)
Create a new Filter using the IS NULL operator.
-
isNotNull
public static Filter isNotNull(String property)
Create a new Filter using the IS NOT NULL operator.
-
isEmpty
public static Filter isEmpty(String property)
Create a new Filter using the IS EMPTY operator.
-
isNotEmpty
public static Filter isNotEmpty(String property)
Create a new Filter using the IS NOT EMPTY operator.
-
and
public static Filter and(Filter... filters)
Create a new Filter using the AND operator.This takes a variable number of parameters. Any number of
Filters can be specified.
-
or
public static Filter or(Filter... filters)
Create a new Filter using the OR operator.This takes a variable number of parameters. Any number of
Filters can be specified.
-
some
public static Filter some(String property, Filter filter)
Create a new Filter using the SOME operator.
-
all
public static Filter all(String property, Filter filter)
Create a new Filter using the ALL operator.
-
none
public static Filter none(String property, Filter filter)
Create a new Filter using the NONE operator. This is equivalent to NOT SOME.
-
custom
public static Filter custom(String expression)
Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}).
Here are some examples:
// Referencing a property in a custom expression Filter.custom("{serialNumber} like '%4780%'"); // comparing two properties Filter.custom("{parent.spotCount} > {spotCount} + 4"); // A constant Filter.custom("1 = 1"); // A function Filter.custom("{dueDate} > current_date()"); // A subquery Filter.custom("{id} in (select pc.cat_id from popular_cats pc where pc.color = 'blue')");- Parameters:
expression- JPQL/HQL where-clause expression
-
custom
public static Filter custom(String expression, Object... values)
Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}). The expression can also contain place holders for the Filter values; these are indicated by JPQL-style positional parameters (i.e. a question mark (?) followed by a number indicating the parameter order, starting with one).
Here are some examples:
// Referencing a property in a custom expression Filter.custom("{serialNumber} like ?1", "%4780%"); // comparing two properties Filter.custom("{parent.spotCount} + ?1 > {spotCount} + ?2", 0, 4); // A constant Filter.custom("?1 = ?2", 1, 1); // A function Filter.custom("?1 > current_date()", someDate); // A subquery Filter.custom("{id} in (select pc.cat_id from popular_cats pc where pc.color = ?1)", "blue");- Parameters:
expression- JPQL/HQL where-clause expressionvalues- one or more values to fill in the numbered placeholders in the expression
-
custom
public static Filter custom(String expression, Collection<?> values)
Create a new Filter using a custom JPQL/HQL expression. This can be any valid where-clause type expression. Reference properties by wrapping them with curly braces ({}). The expression can also contain place holders for the Filter values; these are indicated by JPQL-style positional parameters (i.e. a question mark (?) followed by a number indicating the parameter order, starting with one).
Here are some examples:
// Referencing a property in a custom expression Filter.custom("{serialNumber} like ?1", Collections.singleton("%4780%")); // comparing two properties Filter.custom("{parent.spotCount} + ?1 > {spotCount} + ?2", Arrays.asList(0, 4)); // A constant Filter.custom("?1 = ?2", Arrays.asList(1, 1)); // A function Filter.custom("?1 > current_date()", Collections.singleton(someDate)); // A subquery Filter.custom("{id} in (select pc.cat_id from popular_cats pc where pc.color = ?1)", Collections.singleton("blue"));- Parameters:
expression- JPQL/HQL where-clause expressionvalues- one or more values to fill in the numbered placeholders in the expression
-
add
public void add(Filter filter)
Used with OP_OR and OP_AND filters. These filters take a collection of filters as their value. This method adds a filter to that list.
-
remove
public void remove(Filter filter)
Used with OP_OR and OP_AND filters. These filters take a collection of filters as their value. This method removes a filter from that list.
-
getProperty
public String getProperty()
-
setProperty
public void setProperty(String property)
-
getValue
public Object getValue()
-
setValue
public void setValue(Object value)
-
getOperator
public int getOperator()
-
setOperator
public void setOperator(int operator)
-
getValuesAsList
public List<?> getValuesAsList()
Returns the value as a List, converting if necessary. If the value is a List, it will be returned directly. If it is any other Collection type or if it is an Array, an ArrayList will be returned with all the same elements. If the value is any other non-null value, a List containing just that one value will be returned. If it isnull,nullwill be returned.
-
getValuesAsCollection
public Collection<?> getValuesAsCollection()
Returns the value as a Collection, converting if necessary. If the value is a Collection, it will be returned directly. If it is an Array, an ArrayList will be returned with all the same elements. If the value is any other non-null value, a Set containing just that one value will be returned. If it isnull,nullwill be returned.- Returns:
-
isTakesSingleValue
public boolean isTakesSingleValue()
- Returns:
- true if the operator should have a single value specified.
EQUAL, NOT_EQUAL, LESS_THAN, LESS_OR_EQUAL, GREATER_THAN, GREATER_OR_EQUAL, LIKE, ILIKE
-
isTakesListOfValues
public boolean isTakesListOfValues()
- Returns:
- true if the operator should have a list of values specified.
IN, NOT_IN
-
isTakesNoValue
public boolean isTakesNoValue()
- Returns:
- true if the operator does not require a value to be specified.
NULL, NOT_NULL, EMPTY, NOT_EMPTY
-
isTakesSingleSubFilter
public boolean isTakesSingleSubFilter()
- Returns:
- true if the operator should have a single Filter specified for
the value.
NOT, ALL, SOME, NONE
-
isTakesListOfSubFilters
public boolean isTakesListOfSubFilters()
- Returns:
- true if the operator should have a list of Filters specified for
the value.
AND, OR
-
isTakesNoProperty
public boolean isTakesNoProperty()
- Returns:
- true if the operator does not require a property to be specified.
AND, OR, NOT
-
matches
public boolean matches(MatcherContext context)
-
toQueryString
public String toQueryString()
-
-