Creates standard common expressions for using in a Query Where or Having clause.
You will often not use this class directly but instead just add expressions
via the methods on ExpressionList such as
ExpressionList.gt(String, Object)
.
The ExpressionList is returned from Query.where()
.
// Example: fetch orders where status equals new or orderDate > lastWeek.
Expression newOrLastWeek =
Expr.or(Expr.eq("status", Order.Status.NEW),
Expr.gt("orderDate", lastWeek));
List<Order> list = DB.find(Order.class)
.where().add(newOrLastWeek)
.findList();
...
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAll Equal - Map containing property names and their values.and
(Expression expOne, Expression expTwo) And - join two expressions with a logical and.arrayContains
(String propertyName, Object... values) Array contains all the given values.arrayIsEmpty
(String propertyName) Array is empty - for the given array property.arrayIsNotEmpty
(String propertyName) Array is not empty - for the given array property.arrayNotContains
(String propertyName, Object... values) Array does not contain the given values.Between - property between the two given values.betweenProperties
(String lowProperty, String highProperty, Object value) Between - value between two given properties.bitwiseAll
(String propertyName, long flags) Add expression for ALL of the given bit flags to be set.bitwiseAnd
(String propertyName, long flags, long match) Add bitwise AND expression of the given bit flags to compare with the match/mask.bitwiseAny
(String propertyName, long flags) Add expression for ANY of the given bit flags to be set.<T> Junction<T>
conjunction
(Query<T> query) Return a list of expressions that will be joined by AND's.<T> Junction<T>
conjunction
(Query<T> query, ExpressionList<T> parent) Return a list of expressions that will be joined by AND's.Contains - property like %value%.<T> Junction<T>
disjunction
(Query<T> query) Return a list of expressions that will be joined by OR's.<T> Junction<T>
disjunction
(Query<T> query, ExpressionList<T> parent) Return a list of expressions that will be joined by OR's.Ends With - property like %value.Equal To - property equal to the given value.Equal To or Null - property equal to the given value or null.exampleLike
(Object example) Create the query by Example expression which is case sensitive and using LikeType.RAW (you need to add you own wildcards % and _).exampleLike
(Object example, boolean caseInsensitive, LikeType likeType) Create the query by Example expression specifying more options.Exists expressionGreater Than or Equal to - property greater than or equal to the given value.Greater than or Equal to OR Null (>= or null
)Greater Than - property greater than the given value.Greater Than Or Null - property greater than the given value or null.Case insensitive Contains - property like %value%.Id Equal to - ID property is equal to the value.Id IN a list of Id values.idIn
(Collection<?> idCollection) Id IN a collection of Id values.Case insensitive Ends With - property like %value.Case Insensitive Equal To - property equal to the given value (typically using a lower() function to make it case insensitive).Case Insensitive Equal To that allows for named parameter use.iexampleLike
(Object example) Case insensitiveexampleLike(Object)
Case insensitive Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).In - using a subQuery.In - property has a value in the array of values.in
(String propertyName, Collection<?> values) In - property has a value in the collection of values.Case Insensitive Not Equal To - property not equal to the given value (typically using a lower() function to make it case insensitive).Case Insensitive Not Equal To that allows for named parameter use.inOrEmpty
(String propertyName, Collection<?> values) In where null or empty values means that no predicate is added to the query.In expression using pairs of value objects.In Range -property >= value1 and property < value2
.inRangeWith
(String lowProperty, String highProperty, Object value) Value in Range between 2 properties.Is empty expression for collection properties.isNotEmpty
(String propertyName) Is not empty expression for collection properties.Is Not Null - property is not null.Is Null - property is null.istartsWith
(String propertyName, String value) Case insensitive Starts With - property like value%.jsonBetween
(String propertyName, String path, Object lowerValue, Object upperValue) Between - for the given path in a JSON document.jsonEqualTo
(String propertyName, String path, Object val) Equal to - for the given path in a JSON document.jsonExists
(String propertyName, String path) Path exists - for the given path in a JSON document.jsonGreaterOrEqual
(String propertyName, String path, Object val) Greater than or equal to - for the given path in a JSON document.jsonGreaterThan
(String propertyName, String path, Object val) Greater than - for the given path in a JSON document.jsonLessOrEqualTo
(String propertyName, String path, Object val) Less than or equal to - for the given path in a JSON document.jsonLessThan
(String propertyName, String path, Object val) Less than - for the given path in a JSON document.jsonNotEqualTo
(String propertyName, String path, Object val) Not Equal to - for the given path in a JSON document.jsonNotExists
(String propertyName, String path) Path does not exist - for the given path in a JSON document.<T> Junction<T>
junction
(Junction.Type type, Query<T> query, ExpressionList<T> parent) Return a Text query junction for MUST, SHOULD or MUST NOT.Less Than or Equal to - property less than or equal to the given value.Less Than or Equal to OR Null (<= or null
)Like with support for named parameters.Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).Less Than - property less than the given value.Less Than or Null - property less than the given value or null.Not Equal To - property not equal to the given value.not
(Expression exp) Negate the expression (prefix it with NOT).Not exists expressionNot In - using a subQuery.Not In - property has a value in the array of values.notIn
(String propertyName, Collection<?> values) Not In - property has a value in the collection of values.or
(Expression expOne, Expression expTwo) Or - join two expressions with a logical or.Add raw expression with no parameters.Add raw expression with a single parameter.Add raw expression with an array of parameters.startsWith
(String propertyName, String value) Starts With - property like value%.textCommonTerms
(String search, TextCommonTerms options) Create a text common terms expression (currently doc store/Elastic only).Create a Text Match expression (currently doc store/Elastic only).textMultiMatch
(String query, MultiMatch options) Create a Text Multi match expression (currently doc store/Elastic only).textQueryString
(String search, TextQueryString options) Create a text query string expression (currently doc store/Elastic only).textSimple
(String search, TextSimple options) Create a text simple query expression (currently doc store/Elastic only).<T> void
where
(ExpressionList<T> where, String expressions, Object[] params) Add the expressions to the given expression list.
-
Method Details
-
jsonExists
Path exists - for the given path in a JSON document. -
jsonNotExists
Path does not exist - for the given path in a JSON document. -
jsonEqualTo
Equal to - for the given path in a JSON document. -
jsonNotEqualTo
Not Equal to - for the given path in a JSON document. -
jsonGreaterThan
Greater than - for the given path in a JSON document. -
jsonGreaterOrEqual
Greater than or equal to - for the given path in a JSON document. -
jsonLessThan
Less than - for the given path in a JSON document. -
jsonLessOrEqualTo
Less than or equal to - for the given path in a JSON document. -
jsonBetween
Between - for the given path in a JSON document. -
arrayContains
Array contains all the given values.Array support is effectively limited to Postgres at this time.
-
arrayNotContains
Array does not contain the given values.Array support is effectively limited to Postgres at this time.
-
arrayIsEmpty
Array is empty - for the given array property.Array support is effectively limited to Postgres at this time.
-
arrayIsNotEmpty
Array is not empty - for the given array property.Array support is effectively limited to Postgres at this time.
-
eq
Equal To - property equal to the given value. -
eqOrNull
Equal To or Null - property equal to the given value or null. -
ne
Not Equal To - property not equal to the given value. -
ieq
Case Insensitive Equal To - property equal to the given value (typically using a lower() function to make it case insensitive). -
ine
Case Insensitive Not Equal To - property not equal to the given value (typically using a lower() function to make it case insensitive). -
ieqObject
Case Insensitive Equal To that allows for named parameter use. -
ineObject
Case Insensitive Not Equal To that allows for named parameter use. -
inRange
In Range -property >= value1 and property < value2
.Unlike Between inRange is "half open" and usually more useful for use with dates or timestamps.
-
inRangeWith
Value in Range between 2 properties..startDate.inRangeWith(endDate, now) // which equates to startDate <= now and (endDate > now or endDate is null)
This is a convenience expression combining a number of simple expressions. The most common use of this could be called "effective dating" where 2 date or timestamp columns represent the date range in which
-
between
Between - property between the two given values. -
betweenProperties
Between - value between two given properties. -
gtOrNull
Greater Than Or Null - property greater than the given value or null.A convenient expression combining GT and Is Null. Most often useful for range expressions where the top range value is nullable.
-
geOrNull
Greater than or Equal to OR Null (>= or null
)A convenient expression combining GE and Is Null. Most often useful for range expressions where the top range value is nullable.
-
gt
Greater Than - property greater than the given value. -
ge
Greater Than or Equal to - property greater than or equal to the given value. -
ltOrNull
Less Than or Null - property less than the given value or null.A convenient expression combining LT and Is Null. Most often useful for range expressions where the bottom range value is nullable.
-
leOrNull
Less Than or Equal to OR Null (<= or null
)A convenient expression combining LE and Is Null. Most often useful for range expressions where the bottom range value is nullable.
-
lt
Less Than - property less than the given value. -
le
Less Than or Equal to - property less than or equal to the given value. -
isNull
Is Null - property is null. -
isNotNull
Is Not Null - property is not null. -
iexampleLike
Case insensitiveexampleLike(Object)
-
exampleLike
Create the query by Example expression which is case sensitive and using LikeType.RAW (you need to add you own wildcards % and _). -
exampleLike
Create the query by Example expression specifying more options. -
like
Like with support for named parameters. -
like
Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore). -
ilike
Case insensitive Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore). Typically uses a lower() function to make the expression case insensitive. -
startsWith
Starts With - property like value%. -
istartsWith
Case insensitive Starts With - property like value%. Typically uses a lower() function to make the expression case insensitive. -
endsWith
Ends With - property like %value. -
iendsWith
Case insensitive Ends With - property like %value. Typically uses a lower() function to make the expression case insensitive. -
contains
Contains - property like %value%. -
icontains
Case insensitive Contains - property like %value%. Typically uses a lower() function to make the expression case insensitive. -
inPairs
In expression using pairs of value objects. -
in
In - property has a value in the array of values. -
in
In - using a subQuery. -
in
In - property has a value in the collection of values. -
inOrEmpty
In where null or empty values means that no predicate is added to the query.That is, only add the IN predicate if the values are not null or empty.
Without this we typically need to code an
if
block to only add the IN predicate if the collection is not empty like:Without inOrEmpty()
query.where() // add some predicates .eq("status", Status.NEW); if (ids != null && !ids.isEmpty()) { query.where().in("customer.id", ids); } query.findList();
Using inOrEmpty()
query.where() .eq("status", Status.NEW) .inOrEmpty("customer.id", ids) .findList();
-
notIn
Not In - property has a value in the array of values. -
notIn
Not In - property has a value in the collection of values. -
notIn
Not In - using a subQuery. -
exists
Exists expression -
notExists
Not exists expression -
isEmpty
Is empty expression for collection properties. -
isNotEmpty
Is not empty expression for collection properties. -
idEq
Id Equal to - ID property is equal to the value. -
idIn
Id IN a list of Id values. -
idIn
Id IN a collection of Id values. -
allEq
All Equal - Map containing property names and their values.Expression where all the property names in the map are equal to the corresponding value.
- Parameters:
propertyMap
- a map keyed by property names.
-
bitwiseAny
Add expression for ANY of the given bit flags to be set.- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
bitwiseAll
Add expression for ALL of the given bit flags to be set.- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
bitwiseAnd
Add bitwise AND expression of the given bit flags to compare with the match/mask.- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
raw
Add raw expression with a single parameter.The raw expression should contain a single ? at the location of the parameter.
-
raw
Add raw expression with an array of parameters.The raw expression should contain the same number of ? as there are parameters.
-
raw
Add raw expression with no parameters. -
textMatch
Create a Text Match expression (currently doc store/Elastic only). -
textMultiMatch
Create a Text Multi match expression (currently doc store/Elastic only). -
textSimple
Create a text simple query expression (currently doc store/Elastic only). -
textQueryString
Create a text query string expression (currently doc store/Elastic only). -
textCommonTerms
Create a text common terms expression (currently doc store/Elastic only). -
and
And - join two expressions with a logical and. -
or
Or - join two expressions with a logical or. -
not
Negate the expression (prefix it with NOT). -
conjunction
Return a list of expressions that will be joined by AND's. -
disjunction
Return a list of expressions that will be joined by OR's. -
conjunction
Return a list of expressions that will be joined by AND's. -
disjunction
Return a list of expressions that will be joined by OR's. -
junction
Return a Text query junction for MUST, SHOULD or MUST NOT.This is doc store Elastic only.
-
where
Add the expressions to the given expression list.- Parameters:
where
- The expression list to add the expressions toexpressions
- The expressions that are parsedparams
- Bind parameters to match ? or ?1 bind positions.
-