public class Filter extends Object implements Serializable
A Filter
is used by the Search
class to specify a
restriction on what results should be returned in the search. For example, if
a filter Filter.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)
.
Type | Property and Description |
---|---|
boolean |
isTakesNo
Gets the value of the property takesNoProperty.
|
Modifier and Type | Field and Description |
---|---|
static int |
OP_ALL |
static int |
OP_AND |
static int |
OP_CUSTOM |
static int |
OP_EMPTY |
static int |
OP_EQUAL |
static int |
OP_GREATER_OR_EQUAL |
static int |
OP_GREATER_THAN |
static int |
OP_ILIKE |
static int |
OP_IN |
static int |
OP_LESS_OR_EQUAL |
static int |
OP_LESS_THAN |
static int |
OP_LIKE |
static int |
OP_NONE |
static int |
OP_NOT |
static int |
OP_NOT_EMPTY |
static int |
OP_NOT_EQUAL |
static int |
OP_NOT_IN |
static int |
OP_NOT_NULL |
static int |
OP_NULL |
static int |
OP_OR |
static int |
OP_SOME |
protected int |
operator
The type of comparison to do between the property and the value.
|
protected String |
property
The name of the property to filter on.
|
static String |
ROOT_ENTITY
Property string representing the root entity of the search.
|
protected Object |
value
The value to compare the property with.
|
Constructor and Description |
---|
Filter() |
Filter(Map<String,?> filterAsMap) |
Filter(String property,
Object value) |
Filter(String property,
Object value,
int operator) |
Modifier and Type | Method and Description |
---|---|
void |
add(Filter filter)
Used with OP_OR and OP_AND filters.
|
static Filter |
all(String property,
Filter filter)
Create a new Filter using the ALL operator.
|
static Filter |
and(Filter... filters)
Create a new Filter using the AND operator.
|
static Filter |
custom(String expression)
Create a new Filter using a custom JPQL/HQL expression.
|
static Filter |
custom(String expression,
Collection<?> values)
Create a new Filter using a custom JPQL/HQL expression.
|
static Filter |
custom(String expression,
Object... values)
Create a new Filter using a custom JPQL/HQL expression.
|
static Filter |
equal(String property,
Object value)
Create a new Filter using the == operator.
|
boolean |
equals(Object obj) |
int |
getOperator() |
String |
getProperty() |
Object |
getValue() |
Collection<?> |
getValuesAsCollection()
Returns the value as a Collection, converting if necessary.
|
List<?> |
getValuesAsList()
Returns the value as a List, converting if necessary.
|
static Filter |
greaterOrEqual(String property,
Object value)
Create a new Filter using the >= operator.
|
static Filter |
greaterThan(String property,
Object value)
Create a new Filter using the > operator.
|
int |
hashCode() |
static Filter |
ilike(String property,
String value)
Create a new Filter using the ILIKE operator.
|
static Filter |
in(String property,
Collection<?> value)
Create a new Filter using the IN operator.
|
static Filter |
in(String property,
Object... value)
Create a new Filter using the IN operator.
|
static Filter |
isEmpty(String property)
Create a new Filter using the IS EMPTY operator.
|
static boolean |
isFilter(Map<String,?> filter) |
static Filter |
isNotEmpty(String property)
Create a new Filter using the IS NOT EMPTY operator.
|
static Filter |
isNotNull(String property)
Create a new Filter using the IS NOT NULL operator.
|
static Filter |
isNull(String property)
Create a new Filter using the IS NULL operator.
|
boolean |
isTakesListOfSubFilters() |
boolean |
isTakesListOfValues() |
boolean |
isTakesNoProperty()
Gets the value of the property takesNoProperty.
|
boolean |
isTakesNoValue() |
boolean |
isTakesSingleSubFilter() |
boolean |
isTakesSingleValue() |
static Filter |
lessOrEqual(String property,
Object value)
Create a new Filter using the <= operator.
|
static Filter |
lessThan(String property,
Object value)
Create a new Filter using the < operator.
|
static Filter |
like(String property,
String value)
Create a new Filter using the LIKE operator.
|
boolean |
matches(MatcherContext context) |
static Filter |
none(String property,
Filter filter)
Create a new Filter using the NONE operator.
|
static Filter |
not(Filter filter)
Create a new Filter using the NOT operator.
|
static Filter |
notEqual(String property,
Object value)
Create a new Filter using the != operator.
|
static Filter |
notIn(String property,
Collection<?> value)
Create a new Filter using the NOT IN operator.
|
static Filter |
notIn(String property,
Object... value)
Create a new Filter using the NOT IN operator.
|
static Filter |
or(Filter... filters)
Create a new Filter using the OR operator.
|
static Filter |
reconstructFromMap(Map<String,?> filterAsMap) |
void |
remove(Filter filter)
Used with OP_OR and OP_AND filters.
|
void |
setOperator(int operator) |
void |
setProperty(String property) |
void |
setValue(Object value) |
static Filter |
some(String property,
Filter filter)
Create a new Filter using the SOME operator.
|
String |
toQueryString() |
String |
toString() |
public boolean isTakesNoProperty
public static final String ROOT_ENTITY
protected String property
"name", "dateOfBirth", "employee.age", "employee.spouse.job.title"
protected Object value
"Fred", new Date(), 45
protected int operator
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
.public static final int OP_EQUAL
public static final int OP_NOT_EQUAL
public static final int OP_LESS_THAN
public static final int OP_GREATER_THAN
public static final int OP_LESS_OR_EQUAL
public static final int OP_GREATER_OR_EQUAL
public static final int OP_LIKE
public static final int OP_ILIKE
public static final int OP_IN
public static final int OP_NOT_IN
public static final int OP_NULL
public static final int OP_NOT_NULL
public static final int OP_EMPTY
public static final int OP_NOT_EMPTY
public static final int OP_AND
public static final int OP_OR
public static final int OP_NOT
public static final int OP_SOME
public static final int OP_ALL
public static final int OP_NONE
public static final int OP_CUSTOM
public static Filter equal(String property, Object value)
public static Filter lessThan(String property, Object value)
public static Filter greaterThan(String property, Object value)
public static Filter lessOrEqual(String property, Object value)
public static Filter greaterOrEqual(String property, Object value)
public static Filter in(String property, Collection<?> value)
This takes a variable number of parameters. Any number of values can be specified.
public static Filter in(String property, Object... value)
This takes a variable number of parameters. Any number of values can be specified.
public static Filter notIn(String property, Collection<?> value)
This takes a variable number of parameters. Any number of values can be specified.
public static Filter notIn(String property, Object... value)
This takes a variable number of parameters. Any number of values can be specified.
public static Filter like(String property, String value)
public static Filter ilike(String property, String value)
public static Filter notEqual(String property, Object value)
public static Filter isNotNull(String property)
public static Filter isEmpty(String property)
public static Filter isNotEmpty(String property)
public static Filter and(Filter... filters)
This takes a variable number of parameters. Any number of
Filter
s can be specified.
public static Filter or(Filter... filters)
This takes a variable number of parameters. Any number of
Filter
s can be specified.
public static Filter some(String property, Filter filter)
public static Filter all(String property, Filter filter)
public static Filter none(String property, Filter filter)
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')");
expression
- JPQL/HQL where-clause expressionpublic 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");
expression
- JPQL/HQL where-clause expressionvalues
- one or more values to fill in the numbered placeholders in
the expressionpublic 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"));
expression
- JPQL/HQL where-clause expressionvalues
- one or more values to fill in the numbered placeholders in
the expressionpublic void add(Filter filter)
public void remove(Filter filter)
public String getProperty()
public void setProperty(String property)
public Object getValue()
public void setValue(Object value)
public int getOperator()
public void setOperator(int operator)
public List<?> getValuesAsList()
null
,
null
will be returned.public Collection<?> getValuesAsCollection()
null
, null
will be returned.public boolean isTakesSingleValue()
EQUAL, NOT_EQUAL, LESS_THAN, LESS_OR_EQUAL, GREATER_THAN, GREATER_OR_EQUAL, LIKE, ILIKE
public boolean isTakesListOfValues()
IN, NOT_IN
public boolean isTakesNoValue()
NULL, NOT_NULL, EMPTY, NOT_EMPTY
public boolean isTakesSingleSubFilter()
NOT, ALL, SOME, NONE
public boolean isTakesListOfSubFilters()
AND, OR
public boolean isTakesNoProperty()
public boolean matches(MatcherContext context)
public String toQueryString()
Copyright © 2019. All rights reserved.