Class DefaultExpressionList<T>
- java.lang.Object
-
- io.ebeaninternal.server.expression.DefaultExpressionList<T>
-
- All Implemented Interfaces:
Expression
,ExpressionList<T>
,SpiExpression
,SpiExpressionList<T>
- Direct Known Subclasses:
FilterExpressionList
public class DefaultExpressionList<T> extends Object implements SpiExpressionList<T>
Default implementation of ExpressionList.
-
-
Field Summary
-
Fields inherited from interface io.ebeaninternal.api.SpiExpression
SQL_FALSE, SQL_TRUE
-
-
Constructor Summary
Constructors Constructor Description DefaultExpressionList(Query<T> query)
Construct for Text root expression list - this handles implicit Bool Should, Must etc.DefaultExpressionList(Query<T> query, ExpressionList<T> parentExprList)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExpressionList<T>
add(Expression expr)
Add an Expression to the list.ExpressionList<T>
addAll(ExpressionList<T> exprList)
Add a list of Expressions to this ExpressionList.svoid
addBindValues(SpiExpressionRequest request)
Add the parameter values to be set against query.void
addSql(SpiExpressionRequest request)
Add some sql to the query.ExpressionList<T>
allEq(Map<String,Object> propertyMap)
All Equal - Map containing property names and their values.Junction<T>
and()
Start a list of expressions that will be joined by AND's returning the expression list the expressions are added to.ExpressionList<T>
and(Expression expOne, Expression expTwo)
And - join two expressions with a logical and.Query<T>
apply(FetchPath fetchPath)
Apply the path properties to the query replacing the select and fetch clauses.ExpressionList<T>
arrayContains(String propertyName, Object... elementValue)
Array property contains entries with the given values.ExpressionList<T>
arrayIsEmpty(String propertyName)
Array is empty - for the given array property.ExpressionList<T>
arrayIsNotEmpty(String propertyName)
Array is not empty - for the given array property.ExpressionList<T>
arrayNotContains(String propertyName, Object... values)
Array does not contain the given values.Query<T>
asDraft()
Execute the query against the draft set of tables.<D> DtoQuery<D>
asDto(Class<D> dtoClass)
Convert the query to a DTO bean query.Query<T>
asOf(Timestamp asOf)
Perform an 'As of' query using history tables to return the object graph as of a time in the past.UpdateQuery<T>
asUpdate()
Return the underlying query as an UpdateQuery.ExpressionList<T>
between(String propertyName, Object value1, Object value2)
Between - property between the two given values.ExpressionList<T>
betweenProperties(String lowProperty, String highProperty, Object value)
Between - value between the two properties.ExpressionList<T>
bitwiseAll(String propertyName, long flags)
Add expression for ALL of the given bit flags to be set.ExpressionList<T>
bitwiseAnd(String propertyName, long flags, long match)
Add bitwise AND expression of the given bit flags to compare with the match/mask.ExpressionList<T>
bitwiseAny(String propertyName, long flags)
Add expression for ANY of the given bit flags to be set.ExpressionList<T>
bitwiseNot(String propertyName, long flags)
Add expression for the given bit flags to be NOT set.Junction<T>
conjunction()
Start (and return) a list of expressions that will be joined by AND's.ExpressionList<T>
contains(String propertyName, String value)
Contains - property like %value%.void
containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins)
Return true if one of the expressions is related to a Many property.DefaultExpressionList<T>
copy(Query<T> query)
Return a copy of the expression list.DefaultExpressionList<T>
copyForPlanKey()
Return a copy of the expression for use in the query plan key.int
delete()
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.int
delete(Transaction transaction)
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.Junction<T>
disjunction()
Start (and return) a list of expressions that will be joined by OR's.ExpressionList<T>
endAnd()
End a AND junction - synonym for endJunction().ExpressionList<T>
endJunction()
End a junction returning the parent expression list.ExpressionList<T>
endNot()
End a NOT junction - synonym for endJunction().ExpressionList<T>
endOr()
End a AND junction - synonym for endJunction().ExpressionList<T>
endsWith(String propertyName, String value)
Ends With - property like %value.ExpressionList<T>
eq(String propertyName, Object value)
Equal To - property is equal to a given value.ExpressionList<T>
eqOrNull(String propertyName, Object value)
Equal To or Null - property is equal to a given value or null.ExpressionList<T>
exampleLike(Object example)
A "Query By Example" type of expression.boolean
exists()
Execute the query returning true if a row is found.ExpressionList<T>
exists(Query<?> subQuery)
Exists expressionExpressionList<T>
filterMany(String manyProperty)
Add some filter predicate expressions to the many property.ExpressionList<T>
filterMany(String manyProperty, String expressions, Object... params)
Add filter expressions to the many property.int
findCount()
Return the count of entities this query should return.void
findEach(Consumer<T> consumer)
Execute the query process the beans one at a time.void
findEachWhile(Predicate<T> consumer)
Execute the query processing the beans one at a time with the ability to stop processing before reading all the beans.FutureRowCount<T>
findFutureCount()
Execute find row count query in a background thread.FutureIds<T>
findFutureIds()
Execute find Id's query in a background thread.FutureList<T>
findFutureList()
Execute find list query in a background thread.<A> List<A>
findIds()
Execute the query returning the list of Id's.QueryIterator<T>
findIterate()
Execute the query iterating over the results.List<T>
findList()
Execute the query returning a list.<K> Map<K,T>
findMap()
Execute the query returning a map.T
findOne()
Execute the query returning a single bean or null (if no matching bean is found).Optional<T>
findOneOrEmpty()
Execute the query returning an optional bean.PagedList<T>
findPagedList()
Return a PagedList for this query using firstRow and maxRows.Set<T>
findSet()
Execute the query returning a set.<A> List<A>
findSingleAttributeList()
Execute the query returning a list of values for a single property.List<Version<T>>
findVersions()
Return versions of a @History entity bean.List<Version<T>>
findVersionsBetween(Timestamp start, Timestamp end)
Return versions of a @History entity bean between the 2 timestamps.Query<T>
forUpdate()
Execute using "for update" clause which results in the DB locking the record.Query<T>
forUpdateNoWait()
Execute using "for update" clause with No Wait option.Query<T>
forUpdateSkipLocked()
Execute using "for update" clause with Skip Locked option.ExpressionList<T>
ge(String propertyName, Object value)
Greater Than or Equal to - property greater than or equal to the given value.Object
getIdEqualTo(String idName)
Return the bind Id value if this is a "equal to" expression for the id property.List<SpiExpression>
getUnderlyingList()
Return the underlying list of expressions.ExpressionList<T>
gt(String propertyName, Object value)
Greater Than - property greater than the given value.ExpressionList<T>
gtOrNull(String propertyName, Object value)
Greater Than or Null - property greater than the given value or null.ExpressionList<T>
having()
Add expressions to the having clause.ExpressionList<T>
icontains(String propertyName, String value)
Case insensitive Contains - property like %value%.ExpressionList<T>
idEq(Object value)
Id Equal to - ID property is equal to the value.Object
idEqualTo(String idName)
ExpressionList<T>
idIn(Object... idValues)
Id IN a list of id values.ExpressionList<T>
idIn(Collection<?> idCollection)
Id IN a collection of id values.ExpressionList<T>
iendsWith(String propertyName, String value)
Case insensitive Ends With - property like %value.ExpressionList<T>
ieq(String propertyName, String value)
Case Insensitive Equal To - property equal to the given value (typically using a lower() function to make it case insensitive).ExpressionList<T>
iexampleLike(Object example)
Case insensitive version ofExpressionList.exampleLike(Object)
ExpressionList<T>
ilike(String propertyName, String value)
Case insensitive Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).ExpressionList<T>
in(String propertyName, Query<?> subQuery)
In - using a subQuery.ExpressionList<T>
in(String propertyName, Object... values)
In - property has a value in the array of values.ExpressionList<T>
in(String propertyName, Collection<?> values)
In - property has a value in the collection of values.ExpressionList<T>
ine(String propertyName, String value)
Case Insensitive Not Equal To - property not equal to the given value (typically using a lower() function to make it case insensitive).ExpressionList<T>
inOrEmpty(String propertyName, Collection<?> values)
In where null or empty values means that no predicate is added to the query.ExpressionList<T>
inPairs(Pairs pairs)
In expression using pairs of value objects.ExpressionList<T>
inRange(String propertyName, Object value1, Object value2)
In Range - property >= value1 and property < value2.ExpressionList<T>
inRangeWith(String lowProperty, String highProperty, Object value)
Value in Range between 2 properties.List<SpiExpression>
internalList()
boolean
isEmpty()
Return true if this list is empty.ExpressionList<T>
isEmpty(String propertyName)
Is empty expression for collection properties.ExpressionList<T>
isNotEmpty(String propertyName)
Is not empty expression for collection properties.ExpressionList<T>
isNotNull(String propertyName)
Is Not Null - property is not null.ExpressionList<T>
isNull(String propertyName)
Is Null - property is null.boolean
isSameByBind(SpiExpression other)
Return true if the expression is the same with respect to bind values.ExpressionList<T>
istartsWith(String propertyName, String value)
Case insensitive Starts With - property like value%.ExpressionList<T>
jsonBetween(String propertyName, String path, Object lowerValue, Object upperValue)
Between - for the given path in a JSON document.ExpressionList<T>
jsonEqualTo(String propertyName, String path, Object value)
Equal to expression for the value at the given path in the JSON document.ExpressionList<T>
jsonExists(String propertyName, String path)
Path exists - for the given path in a JSON document.ExpressionList<T>
jsonGreaterOrEqual(String propertyName, String path, Object val)
Greater than or equal to - for the given path in a JSON document.ExpressionList<T>
jsonGreaterThan(String propertyName, String path, Object val)
Greater than - for the given path in a JSON document.ExpressionList<T>
jsonLessOrEqualTo(String propertyName, String path, Object val)
Less than or equal to - for the given path in a JSON document.ExpressionList<T>
jsonLessThan(String propertyName, String path, Object val)
Less than - for the given path in a JSON document.ExpressionList<T>
jsonNotEqualTo(String propertyName, String path, Object val)
Not Equal to - for the given path in a JSON document.ExpressionList<T>
jsonNotExists(String propertyName, String path)
Path does not exist - for the given path in a JSON document.ExpressionList<T>
le(String propertyName, Object value)
Less Than or Equal to - property less than or equal to the given value.ExpressionList<T>
like(String propertyName, String value)
Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).ExpressionList<T>
lt(String propertyName, Object value)
Less Than - property less than the given value.ExpressionList<T>
ltOrNull(String propertyName, Object value)
Less Than or Null - property less than the given value or null.ExpressionList<T>
match(String propertyName, String search)
Add a match expression.ExpressionList<T>
match(String propertyName, String search, Match options)
Add a match expression with options.ExpressionList<T>
multiMatch(String query, MultiMatch options)
Add a multi-match expression using options.ExpressionList<T>
multiMatch(String query, String... fields)
Add a multi-match expression.Junction<T>
must()
Start a list of expressions that will be joined by MUST.Junction<T>
mustNot()
Start a list of expressions that will be joined by MUST NOT.boolean
naturalKey(NaturalKeyQueryData<?> data)
Check for match to a natural key query returning false if it doesn't match.ExpressionList<T>
ne(String propertyName, Object value)
Not Equal To - property not equal to the given value.String
nestedPath(BeanDescriptor<?> desc)
Return the nested path for this expression.Junction<T>
not()
Return a list of expressions that will be wrapped by NOT.ExpressionList<T>
not(Expression exp)
Negate the expression (prefix it with NOT).ExpressionList<T>
notExists(Query<?> subQuery)
Not exists expressionExpressionList<T>
notIn(String propertyName, Query<?> subQuery)
Not In - using a subQuery.ExpressionList<T>
notIn(String propertyName, Object... values)
Not In - property has a value in the array of values.ExpressionList<T>
notIn(String propertyName, Collection<?> values)
Not In - property has a value in the collection of values.Junction<T>
or()
Return a list of expressions that will be joined by OR's.ExpressionList<T>
or(Expression expOne, Expression expTwo)
Or - join two expressions with a logical or.OrderBy<T>
order()
Return the OrderBy so that you can append an ascending or descending property to the order by clause.ExpressionList<T>
order(String orderByClause)
Set the order by clause replacing the existing order by clause if there is one.OrderBy<T>
orderBy()
Return the OrderBy so that you can append an ascending or descending property to the order by clause.ExpressionList<T>
orderBy(String orderBy)
Set the order by clause replacing the existing order by clause if there is one.Query<T>
orderById(boolean orderById)
Controls, if paginated queries should always append an 'order by id' statement at the end to guarantee a deterministic sort result.void
prepareDocNested(BeanDescriptor<T> beanDescriptor)
Prepare expressions for document store nested path handling.void
prepareExpression(BeanQueryRequest<?> request)
Prepare the expression.Query<T>
query()
Return the query that owns this expression list.int
queryBindHash()
Calculate a hash based on the expressions.void
queryPlanHash(StringBuilder builder)
Calculate a hash based on the expressions but excluding the actual bind values.ExpressionList<T>
raw(String raw)
Add raw expression with no parameters.ExpressionList<T>
raw(String raw, Object value)
Add raw expression with a single parameter.ExpressionList<T>
raw(String raw, Object... values)
Add raw expression with an array of parameters.ExpressionList<T>
rawOrEmpty(String raw, Collection<?> values)
Only add the raw expression if the values is not null or empty.Query<T>
select(FetchGroup<T> fetchGroup)
Apply the fetchGroup which defines what part of the object graph to load.Query<T>
select(String fetchProperties)
Specify specific properties to fetch on the main/root bean (aka partial object).void
setAllDocNested(String allDocNestedPath)
Set the nested path that all contained expressions share.Query<T>
setBeanCacheMode(CacheMode useCache)
Set the mode to use the bean cache when executing this query.Query<T>
setCountDistinct(CountDistinctOrder orderBy)
Extended version for setDistinct in conjunction with "findSingleAttributeList";Query<T>
setDisableLazyLoading(boolean disableLazyLoading)
Set true if you want to disable lazy loading.Query<T>
setDisableReadAuditing()
Disable read auditing for this query.Query<T>
setDistinct(boolean distinct)
Set whether this query uses DISTINCT.Query<T>
setDocIndexName(String indexName)
Set the index(es) to search for a document store which uses partitions.ExpressionList<T>
setFirstRow(int firstRow)
Set the first row to fetch.Query<T>
setIncludeSoftDeletes()
Execute the query including soft deleted rows.Query<T>
setLabel(String label)
Set a label on the query (to help identify query execution statistics).Query<T>
setMapKey(String mapKey)
Set the name of the property which values become the key of a map.ExpressionList<T>
setMaxRows(int maxRows)
Set the maximum number of rows to fetch.Query<T>
setOrderBy(String orderBy)
Deprecated migrate toExpressionList.orderBy(String)
void
setUnderlying(List<SpiExpression> groupedByNesting)
Replace the underlying expression list with one organised by nested path.Query<T>
setUseCache(boolean useCache)
Set to true when this query should use the bean cache.Query<T>
setUseDocStore(boolean useDocsStore)
Set to true if this query should execute against the doc store.Query<T>
setUseQueryCache(CacheMode useCache)
Set theCacheMode
to use the query cache for executing this query.Junction<T>
should()
Start a list of expressions that will be joined by SHOULD.void
simplify()
Simplify nested expressions if possible.ExpressionList<T>
startsWith(String propertyName, String value)
Starts With - property like value%.ExpressionList<T>
textCommonTerms(String search, TextCommonTerms options)
Add common terms expression.ExpressionList<T>
textQueryString(String search, TextQueryString options)
Add a query string expression.ExpressionList<T>
textSimple(String search, TextSimple options)
Add a simple query string expression.Junction<T>
toJunction()
Return the expression list as a Junction (for ElasticSearch).SpiExpressionList<?>
trimPath(int prefixTrim)
Return a copy of the ExpressionList with the path trimmed for filterMany() expressions.int
update()
Execute as a update query.int
update(Transaction transaction)
Execute as a update query with the given transaction.Query<T>
usingConnection(Connection connection)
Execute the query using the given connection.Query<T>
usingTransaction(Transaction transaction)
Execute the query using the given transaction.void
validate(SpiExpressionValidation validation)
Validate all the properties/paths associated with this expression.ExpressionList<T>
where()
Add another expression to the where clause.ExpressionList<T>
where(String expressions, Object... params)
Add the expressions to this expression list.void
writeDocQuery(DocQueryContext context)
Write being aware if it is the Top level "text" expressions.void
writeDocQuery(DocQueryContext context, SpiExpression idEquals)
Write the top level where expressions taking into account possible extra idEquals expression.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.ebean.ExpressionList
findSingleAttribute, isIn, isIn, isIn, setUseQueryCache
-
Methods inherited from interface io.ebeaninternal.api.SpiExpressionList
applyRowLimits
-
-
-
-
Constructor Detail
-
DefaultExpressionList
public DefaultExpressionList(Query<T> query)
Construct for Text root expression list - this handles implicit Bool Should, Must etc.
-
DefaultExpressionList
public DefaultExpressionList(Query<T> query, ExpressionList<T> parentExprList)
-
-
Method Detail
-
toJunction
public Junction<T> toJunction()
Description copied from interface:SpiExpressionList
Return the expression list as a Junction (for ElasticSearch).- Specified by:
toJunction
in interfaceSpiExpressionList<T>
-
naturalKey
public boolean naturalKey(NaturalKeyQueryData<?> data)
Description copied from interface:SpiExpression
Check for match to a natural key query returning false if it doesn't match.- Specified by:
naturalKey
in interfaceSpiExpression
-
simplify
public void simplify()
Description copied from interface:SpiExpression
Simplify nested expressions if possible.- Specified by:
simplify
in interfaceSpiExpression
-
writeDocQuery
public void writeDocQuery(DocQueryContext context) throws IOException
Write being aware if it is the Top level "text" expressions.If this is the Top level "text" expressions then it detects if explicit or implicit Bool Should, Must etc is required to wrap the expressions.
If implicit Bool is required SHOULD is used.
- Specified by:
writeDocQuery
in interfaceSpiExpression
- Throws:
IOException
-
writeDocQuery
public void writeDocQuery(DocQueryContext context, SpiExpression idEquals) throws IOException
Description copied from interface:SpiExpressionList
Write the top level where expressions taking into account possible extra idEquals expression.- Specified by:
writeDocQuery
in interfaceSpiExpressionList<T>
- Throws:
IOException
-
trimPath
public SpiExpressionList<?> trimPath(int prefixTrim)
Description copied from interface:SpiExpressionList
Return a copy of the ExpressionList with the path trimmed for filterMany() expressions.- Specified by:
trimPath
in interfaceSpiExpressionList<T>
-
internalList
public List<SpiExpression> internalList()
-
copy
public DefaultExpressionList<T> copy(Query<T> query)
Return a copy of the expression list.Each of the expressions are expected to be immutable and safe to reference.
-
copyForPlanKey
public DefaultExpressionList<T> copyForPlanKey()
Description copied from interface:SpiExpression
Return a copy of the expression for use in the query plan key.- Specified by:
copyForPlanKey
in interfaceSpiExpression
-
getIdEqualTo
public Object getIdEqualTo(String idName)
Description copied from interface:SpiExpression
Return the bind Id value if this is a "equal to" expression for the id property.- Specified by:
getIdEqualTo
in interfaceSpiExpression
-
containsMany
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins whereManyJoins)
Return true if one of the expressions is related to a Many property.- Specified by:
containsMany
in interfaceSpiExpression
-
validate
public void validate(SpiExpressionValidation validation)
Description copied from interface:SpiExpression
Validate all the properties/paths associated with this expression.- Specified by:
validate
in interfaceSpiExpression
-
query
public Query<T> query()
Description copied from interface:ExpressionList
Return the query that owns this expression list.This is a convenience method solely to support a fluid API where the methods are chained together. Adding expressions returns this expression list and this method can be used after that to return back the original query so that further things can be added to it.
- Specified by:
query
in interfaceExpressionList<T>
-
asOf
public Query<T> asOf(Timestamp asOf)
Description copied from interface:ExpressionList
Perform an 'As of' query using history tables to return the object graph as of a time in the past.To perform this query the DB must have underlying history tables.
- Specified by:
asOf
in interfaceExpressionList<T>
- Parameters:
asOf
- the date time in the past at which you want to view the data
-
asDraft
public Query<T> asDraft()
Description copied from interface:ExpressionList
Execute the query against the draft set of tables.- Specified by:
asDraft
in interfaceExpressionList<T>
-
asDto
public <D> DtoQuery<D> asDto(Class<D> dtoClass)
Description copied from interface:ExpressionList
Convert the query to a DTO bean query.We effectively use the underlying ORM query to build the SQL and then execute and map it into DTO beans.
- Specified by:
asDto
in interfaceExpressionList<T>
-
asUpdate
public UpdateQuery<T> asUpdate()
Description copied from interface:ExpressionList
Return the underlying query as an UpdateQuery.Typically this is used with query beans to covert a query bean query into an UpdateQuery like the examples below.
int rowsUpdated = new QCustomer() .name.startsWith("Rob") .asUpdate() .set("active", false) .update();;
int rowsUpdated = new QContact() .notes.note.startsWith("Make Inactive") .email.endsWith("@foo.com") .customer.id.equalTo(42) .asUpdate() .set("inactive", true) .setRaw("email = lower(email)") .update();
- Specified by:
asUpdate
in interfaceExpressionList<T>
-
setIncludeSoftDeletes
public Query<T> setIncludeSoftDeletes()
Description copied from interface:ExpressionList
Execute the query including soft deleted rows.- Specified by:
setIncludeSoftDeletes
in interfaceExpressionList<T>
-
findVersions
public List<Version<T>> findVersions()
Description copied from interface:ExpressionList
Return versions of a @History entity bean.Generally this query is expected to be a find by id or unique predicates query. It will execute the query against the history returning the versions of the bean.
- Specified by:
findVersions
in interfaceExpressionList<T>
-
findVersionsBetween
public List<Version<T>> findVersionsBetween(Timestamp start, Timestamp end)
Description copied from interface:ExpressionList
Return versions of a @History entity bean between the 2 timestamps.Generally this query is expected to be a find by id or unique predicates query. It will execute the query against the history returning the versions of the bean.
- Specified by:
findVersionsBetween
in interfaceExpressionList<T>
-
where
public ExpressionList<T> where()
Description copied from interface:ExpressionList
Add another expression to the where clause.- Specified by:
where
in interfaceExpressionList<T>
-
order
public OrderBy<T> order()
Description copied from interface:ExpressionList
Return the OrderBy so that you can append an ascending or descending property to the order by clause.This will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is the same as
orderBy()
- Specified by:
order
in interfaceExpressionList<T>
-
orderBy
public OrderBy<T> orderBy()
Description copied from interface:ExpressionList
Return the OrderBy so that you can append an ascending or descending property to the order by clause.This will never return a null. If no order by clause exists then an 'empty' OrderBy object is returned.
This is the same as
order()
- Specified by:
orderBy
in interfaceExpressionList<T>
-
order
public ExpressionList<T> order(String orderByClause)
Description copied from interface:ExpressionList
Set the order by clause replacing the existing order by clause if there is one.This follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
- Specified by:
order
in interfaceExpressionList<T>
-
orderBy
public ExpressionList<T> orderBy(String orderBy)
Description copied from interface:ExpressionList
Set the order by clause replacing the existing order by clause if there is one.This follows SQL syntax using commas between each property with the optional asc and desc keywords representing ascending and descending order respectively.
- Specified by:
orderBy
in interfaceExpressionList<T>
-
setOrderBy
public Query<T> setOrderBy(String orderBy)
Description copied from interface:ExpressionList
Deprecated migrate toExpressionList.orderBy(String)
- Specified by:
setOrderBy
in interfaceExpressionList<T>
-
orderById
public Query<T> orderById(boolean orderById)
Description copied from interface:ExpressionList
Controls, if paginated queries should always append an 'order by id' statement at the end to guarantee a deterministic sort result. This may affect performance. If this is not enabled, and an orderBy is set on the query, it's up to the programmer that this query provides a deterministic result.- Specified by:
orderById
in interfaceExpressionList<T>
-
apply
public Query<T> apply(FetchPath fetchPath)
Description copied from interface:ExpressionList
Apply the path properties to the query replacing the select and fetch clauses.- Specified by:
apply
in interfaceExpressionList<T>
-
usingTransaction
public Query<T> usingTransaction(Transaction transaction)
Description copied from interface:ExpressionList
Execute the query using the given transaction.- Specified by:
usingTransaction
in interfaceExpressionList<T>
-
usingConnection
public Query<T> usingConnection(Connection connection)
Description copied from interface:ExpressionList
Execute the query using the given connection.- Specified by:
usingConnection
in interfaceExpressionList<T>
-
delete
public int delete()
Description copied from interface:ExpressionList
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.Note that if the query includes joins then the generated delete statement may not be optimal depending on the database platform.
- Specified by:
delete
in interfaceExpressionList<T>
- Returns:
- the number of rows that were deleted.
-
delete
public int delete(Transaction transaction)
Description copied from interface:ExpressionList
Execute as a delete query deleting the 'root level' beans that match the predicates in the query.Note that if the query includes joins then the generated delete statement may not be optimal depending on the database platform.
- Specified by:
delete
in interfaceExpressionList<T>
- Returns:
- the number of rows that were deleted.
-
update
public int update()
Description copied from interface:ExpressionList
Execute as a update query.- Specified by:
update
in interfaceExpressionList<T>
- Returns:
- the number of rows that were updated.
- See Also:
UpdateQuery
-
update
public int update(Transaction transaction)
Description copied from interface:ExpressionList
Execute as a update query with the given transaction.- Specified by:
update
in interfaceExpressionList<T>
- Returns:
- the number of rows that were updated.
- See Also:
UpdateQuery
-
findFutureIds
public FutureIds<T> findFutureIds()
Description copied from interface:ExpressionList
Execute find Id's query in a background thread.This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
- Specified by:
findFutureIds
in interfaceExpressionList<T>
- Returns:
- a Future object for the list of Id's
-
findFutureCount
public FutureRowCount<T> findFutureCount()
Description copied from interface:ExpressionList
Execute find row count query in a background thread.This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
- Specified by:
findFutureCount
in interfaceExpressionList<T>
- Returns:
- a Future object for the row count query
-
findFutureList
public FutureList<T> findFutureList()
Description copied from interface:ExpressionList
Execute find list query in a background thread.This returns a Future object which can be used to cancel, check the execution status (isDone etc) and get the value (with or without a timeout).
- Specified by:
findFutureList
in interfaceExpressionList<T>
- Returns:
- a Future object for the list result of the query
-
findPagedList
public PagedList<T> findPagedList()
Description copied from interface:ExpressionList
Return a PagedList for this query using firstRow and maxRows.The benefit of using this over findList() is that it provides functionality to get the total row count etc.
If maxRows is not set on the query prior to calling findPagedList() then a PersistenceException is thrown.
PagedList<Order> pagedList = DB.find(Order.class) .setFirstRow(50) .setMaxRows(20) .findPagedList(); // fetch the total row count in the background pagedList.loadRowCount(); List<Order> orders = pagedList.getList(); int totalRowCount = pagedList.getTotalRowCount();
- Specified by:
findPagedList
in interfaceExpressionList<T>
- Returns:
- The PagedList
- See Also:
Query.findPagedList()
-
findCount
public int findCount()
Description copied from interface:ExpressionList
Return the count of entities this query should return.This is the number of 'top level' or 'root level' entities.
- Specified by:
findCount
in interfaceExpressionList<T>
-
findIds
public <A> List<A> findIds()
Description copied from interface:ExpressionList
Execute the query returning the list of Id's.- Specified by:
findIds
in interfaceExpressionList<T>
- See Also:
Query.findIds()
-
findIterate
public QueryIterator<T> findIterate()
Description copied from interface:ExpressionList
Execute the query iterating over the results.- Specified by:
findIterate
in interfaceExpressionList<T>
- See Also:
Query.findIterate()
-
findEach
public void findEach(Consumer<T> consumer)
Description copied from interface:ExpressionList
Execute the query process the beans one at a time.- Specified by:
findEach
in interfaceExpressionList<T>
- See Also:
Query.findEach(Consumer)
-
findEachWhile
public void findEachWhile(Predicate<T> consumer)
Description copied from interface:ExpressionList
Execute the query processing the beans one at a time with the ability to stop processing before reading all the beans.- Specified by:
findEachWhile
in interfaceExpressionList<T>
- See Also:
Query.findEachWhile(Predicate)
-
findList
public List<T> findList()
Description copied from interface:ExpressionList
Execute the query returning a list.- Specified by:
findList
in interfaceExpressionList<T>
- See Also:
Query.findList()
-
findSet
public Set<T> findSet()
Description copied from interface:ExpressionList
Execute the query returning a set.- Specified by:
findSet
in interfaceExpressionList<T>
- See Also:
Query.findSet()
-
findMap
public <K> Map<K,T> findMap()
Description copied from interface:ExpressionList
Execute the query returning a map.- Specified by:
findMap
in interfaceExpressionList<T>
- See Also:
Query.findMap()
-
findSingleAttributeList
public <A> List<A> findSingleAttributeList()
Description copied from interface:ExpressionList
Execute the query returning a list of values for a single property.Example 1:
List<String> names = DB.find(Customer.class) .select("name") .order().asc("name") .findSingleAttributeList();
Example 2:
List<String> names = DB.find(Customer.class) .setDistinct(true) .select("name") .where().eq("status", Customer.Status.NEW) .order().asc("name") .setMaxRows(100) .findSingleAttributeList();
- Specified by:
findSingleAttributeList
in interfaceExpressionList<T>
- Returns:
- the list of values for the selected property
-
exists
public boolean exists()
Description copied from interface:ExpressionList
Execute the query returning true if a row is found.The query is executed using max rows of 1 and will only select the id property. This method is really just a convenient way to optimise a query to perform a 'does a row exist in the db' check.
Example:
boolean userExists = query().where().eq("email", "[email protected]").exists();
Example using a query bean:
boolean userExists = new QContact().email.equalTo("[email protected]").exists();
- Specified by:
exists
in interfaceExpressionList<T>
- Returns:
- True if the query finds a matching row in the database
-
findOne
public T findOne()
Description copied from interface:ExpressionList
Execute the query returning a single bean or null (if no matching bean is found).If more than 1 row is found for this query then a NonUniqueResultException is thrown.
- Specified by:
findOne
in interfaceExpressionList<T>
- See Also:
Query.findOne()
-
findOneOrEmpty
public Optional<T> findOneOrEmpty()
Description copied from interface:ExpressionList
Execute the query returning an optional bean.- Specified by:
findOneOrEmpty
in interfaceExpressionList<T>
-
filterMany
public ExpressionList<T> filterMany(String manyProperty)
Description copied from interface:ExpressionList
Add some filter predicate expressions to the many property.- Specified by:
filterMany
in interfaceExpressionList<T>
-
filterMany
public ExpressionList<T> filterMany(String manyProperty, String expressions, Object... params)
Description copied from interface:ExpressionList
Add filter expressions to the many property.DB.find(Customer.class) .where() .eq("name", "Rob") .filterMany("orders", "status = ?", Status.NEW) .findList();
- Specified by:
filterMany
in interfaceExpressionList<T>
- Parameters:
manyProperty
- The many propertyexpressions
- Filter expressions with and, or and ? or ?1 type bind parametersparams
- Bind parameters used in the expressions
-
forUpdate
public Query<T> forUpdate()
Description copied from interface:ExpressionList
Execute using "for update" clause which results in the DB locking the record.- Specified by:
forUpdate
in interfaceExpressionList<T>
-
forUpdateNoWait
public Query<T> forUpdateNoWait()
Description copied from interface:ExpressionList
Execute using "for update" clause with No Wait option.This is typically a Postgres and Oracle only option at this stage.
- Specified by:
forUpdateNoWait
in interfaceExpressionList<T>
-
forUpdateSkipLocked
public Query<T> forUpdateSkipLocked()
Description copied from interface:ExpressionList
Execute using "for update" clause with Skip Locked option.This is typically a Postgres and Oracle only option at this stage.
- Specified by:
forUpdateSkipLocked
in interfaceExpressionList<T>
-
select
public Query<T> select(String fetchProperties)
Description copied from interface:ExpressionList
Specify specific properties to fetch on the main/root bean (aka partial object).- Specified by:
select
in interfaceExpressionList<T>
- See Also:
Query.select(String)
-
select
public Query<T> select(FetchGroup<T> fetchGroup)
Description copied from interface:ExpressionList
Apply the fetchGroup which defines what part of the object graph to load.- Specified by:
select
in interfaceExpressionList<T>
-
setDistinct
public Query<T> setDistinct(boolean distinct)
Description copied from interface:ExpressionList
Set whether this query uses DISTINCT.The select() clause MUST be specified when setDistinct(true) is set. The reason for this is that generally ORM queries include the "id" property and this doesn't make sense for distinct queries.
List<Customer> customers = DB.find(Customer.class) .setDistinct(true) .select("name") // only select the customer name .findList();
- Specified by:
setDistinct
in interfaceExpressionList<T>
-
setDocIndexName
public Query<T> setDocIndexName(String indexName)
Description copied from interface:ExpressionList
Set the index(es) to search for a document store which uses partitions.For example, when executing a query against ElasticSearch with daily indexes we can explicitly specify the indexes to search against.
- Specified by:
setDocIndexName
in interfaceExpressionList<T>
- Parameters:
indexName
- The index or indexes to search against- Returns:
- This query
- See Also:
Query.setDocIndexName(String)
-
setFirstRow
public ExpressionList<T> setFirstRow(int firstRow)
Description copied from interface:ExpressionList
Set the first row to fetch.- Specified by:
setFirstRow
in interfaceExpressionList<T>
- See Also:
Query.setFirstRow(int)
-
setMaxRows
public ExpressionList<T> setMaxRows(int maxRows)
Description copied from interface:ExpressionList
Set the maximum number of rows to fetch.- Specified by:
setMaxRows
in interfaceExpressionList<T>
- See Also:
Query.setMaxRows(int)
-
setMapKey
public Query<T> setMapKey(String mapKey)
Description copied from interface:ExpressionList
Set the name of the property which values become the key of a map.- Specified by:
setMapKey
in interfaceExpressionList<T>
- See Also:
Query.setMapKey(String)
-
setUseCache
public Query<T> setUseCache(boolean useCache)
Description copied from interface:ExpressionList
Set to true when this query should use the bean cache.This is now the same as setUseBeanCache(CacheMode.ON) and will be deprecated.
- Specified by:
setUseCache
in interfaceExpressionList<T>
- See Also:
Query.setUseCache(boolean)
-
setBeanCacheMode
public Query<T> setBeanCacheMode(CacheMode useCache)
Description copied from interface:ExpressionList
Set the mode to use the bean cache when executing this query.- Specified by:
setBeanCacheMode
in interfaceExpressionList<T>
- See Also:
Query.setBeanCacheMode(CacheMode)
-
setUseQueryCache
public Query<T> setUseQueryCache(CacheMode useCache)
Description copied from interface:ExpressionList
Set theCacheMode
to use the query cache for executing this query.- Specified by:
setUseQueryCache
in interfaceExpressionList<T>
- See Also:
Query.setUseQueryCache(boolean)
-
setCountDistinct
public Query<T> setCountDistinct(CountDistinctOrder orderBy)
Description copied from interface:ExpressionList
Extended version for setDistinct in conjunction with "findSingleAttributeList";List<CountedValue<Order.Status>> orderStatusCount = DB.find(Order.class) .select("status") .where() .gt("orderDate", LocalDate.now().minusMonths(3)) // fetch as single attribute with a COUNT .setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC) .findSingleAttributeList(); for (CountedValue<Order.Status> entry : orderStatusCount) { System.out.println(" count:" + entry.getCount()+" orderStatus:" + entry.getValue() ); } // produces count:3 orderStatus:NEW count:1 orderStatus:SHIPPED count:1 orderStatus:COMPLETE
- Specified by:
setCountDistinct
in interfaceExpressionList<T>
-
setUseDocStore
public Query<T> setUseDocStore(boolean useDocsStore)
Description copied from interface:ExpressionList
Set to true if this query should execute against the doc store.When setting this you may also consider disabling lazy loading.
- Specified by:
setUseDocStore
in interfaceExpressionList<T>
-
setDisableLazyLoading
public Query<T> setDisableLazyLoading(boolean disableLazyLoading)
Description copied from interface:ExpressionList
Set true if you want to disable lazy loading.That is, once the object graph is returned further lazy loading is disabled.
- Specified by:
setDisableLazyLoading
in interfaceExpressionList<T>
-
setDisableReadAuditing
public Query<T> setDisableReadAuditing()
Description copied from interface:ExpressionList
Disable read auditing for this query.This is intended to be used when the query is not a user initiated query and instead part of the internal processing in an application to load a cache or document store etc. In these cases we don't want the query to be part of read auditing.
- Specified by:
setDisableReadAuditing
in interfaceExpressionList<T>
-
setLabel
public Query<T> setLabel(String label)
Description copied from interface:ExpressionList
Set a label on the query (to help identify query execution statistics).- Specified by:
setLabel
in interfaceExpressionList<T>
-
having
public ExpressionList<T> having()
Description copied from interface:ExpressionList
Add expressions to the having clause.The having clause is only used for queries based on raw sql (via SqlSelect annotation etc).
- Specified by:
having
in interfaceExpressionList<T>
-
add
public ExpressionList<T> add(Expression expr)
Description copied from interface:ExpressionList
Add an Expression to the list.- Specified by:
add
in interfaceExpressionList<T>
-
addAll
public ExpressionList<T> addAll(ExpressionList<T> exprList)
Description copied from interface:ExpressionList
Add a list of Expressions to this ExpressionList.s- Specified by:
addAll
in interfaceExpressionList<T>
-
getUnderlyingList
public List<SpiExpression> getUnderlyingList()
Description copied from interface:SpiExpressionList
Return the underlying list of expressions.- Specified by:
getUnderlyingList
in interfaceSpiExpressionList<T>
-
isEmpty
public boolean isEmpty()
Description copied from interface:SpiExpressionList
Return true if this list is empty.- Specified by:
isEmpty
in interfaceSpiExpressionList<T>
-
addSql
public void addSql(SpiExpressionRequest request)
Description copied from interface:SpiExpression
Add some sql to the query.This will contain ? as a place holder for each associated bind values.
The 'sql' added to the query can contain object property names rather than db tables and columns. This 'sql' is later parsed converting the logical property names to their full database column names.
- Specified by:
addSql
in interfaceSpiExpression
- Parameters:
request
- the associated request.
-
addBindValues
public void addBindValues(SpiExpressionRequest request)
Description copied from interface:SpiExpression
Add the parameter values to be set against query. For each ? place holder there should be a corresponding value that is added to the bindList.- Specified by:
addBindValues
in interfaceSpiExpression
- Parameters:
request
- the associated request.
-
prepareExpression
public void prepareExpression(BeanQueryRequest<?> request)
Description copied from interface:SpiExpression
Prepare the expression. For example, compile sub-query expressions etc.- Specified by:
prepareExpression
in interfaceSpiExpression
-
queryPlanHash
public void queryPlanHash(StringBuilder builder)
Calculate a hash based on the expressions but excluding the actual bind values.- Specified by:
queryPlanHash
in interfaceSpiExpression
-
queryBindHash
public int queryBindHash()
Calculate a hash based on the expressions.- Specified by:
queryBindHash
in interfaceSpiExpression
-
isSameByBind
public boolean isSameByBind(SpiExpression other)
Description copied from interface:SpiExpression
Return true if the expression is the same with respect to bind values.- Specified by:
isSameByBind
in interfaceSpiExpression
-
jsonExists
public ExpressionList<T> jsonExists(String propertyName, String path)
Path exists - for the given path in a JSON document.- Specified by:
jsonExists
in interfaceExpressionList<T>
- Parameters:
propertyName
- the property that holds a JSON documentpath
- the nested path in the JSON document in dot notation
-
jsonNotExists
public ExpressionList<T> jsonNotExists(String propertyName, String path)
Path does not exist - for the given path in a JSON document.- Specified by:
jsonNotExists
in interfaceExpressionList<T>
- Parameters:
propertyName
- the property that holds a JSON documentpath
- the nested path in the JSON document in dot notation
-
jsonEqualTo
public ExpressionList<T> jsonEqualTo(String propertyName, String path, Object value)
Equal to expression for the value at the given path in the JSON document.- Specified by:
jsonEqualTo
in interfaceExpressionList<T>
- Parameters:
propertyName
- the property that holds a JSON documentpath
- the nested path in the JSON document in dot notationvalue
- the value used to test against the document path's value
-
jsonNotEqualTo
public ExpressionList<T> jsonNotEqualTo(String propertyName, String path, Object val)
Not Equal to - for the given path in a JSON document.- Specified by:
jsonNotEqualTo
in interfaceExpressionList<T>
- Parameters:
propertyName
- the property that holds a JSON documentpath
- the nested path in the JSON document in dot notationval
- the value used to test against the document path's value
-
jsonGreaterThan
public ExpressionList<T> jsonGreaterThan(String propertyName, String path, Object val)
Greater than - for the given path in a JSON document.- Specified by:
jsonGreaterThan
in interfaceExpressionList<T>
-
jsonGreaterOrEqual
public ExpressionList<T> jsonGreaterOrEqual(String propertyName, String path, Object val)
Greater than or equal to - for the given path in a JSON document.- Specified by:
jsonGreaterOrEqual
in interfaceExpressionList<T>
-
jsonLessThan
public ExpressionList<T> jsonLessThan(String propertyName, String path, Object val)
Less than - for the given path in a JSON document.- Specified by:
jsonLessThan
in interfaceExpressionList<T>
-
jsonLessOrEqualTo
public ExpressionList<T> jsonLessOrEqualTo(String propertyName, String path, Object val)
Less than or equal to - for the given path in a JSON document.- Specified by:
jsonLessOrEqualTo
in interfaceExpressionList<T>
-
jsonBetween
public ExpressionList<T> jsonBetween(String propertyName, String path, Object lowerValue, Object upperValue)
Between - for the given path in a JSON document.- Specified by:
jsonBetween
in interfaceExpressionList<T>
-
where
public ExpressionList<T> where(String expressions, Object... params)
Description copied from interface:ExpressionList
Add the expressions to this expression list.- Specified by:
where
in interfaceExpressionList<T>
- Parameters:
expressions
- The expressions that are parsed and added to this expression listparams
- Bind parameters to match ? or ?1 bind positions.
-
bitwiseAny
public ExpressionList<T> bitwiseAny(String propertyName, long flags)
Description copied from interface:ExpressionList
Add expression for ANY of the given bit flags to be set.where().bitwiseAny("flags", BwFlags.HAS_BULK + BwFlags.HAS_COLOUR)
- Specified by:
bitwiseAny
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
bitwiseNot
public ExpressionList<T> bitwiseNot(String propertyName, long flags)
Description copied from interface:ExpressionList
Add expression for the given bit flags to be NOT set.where().bitwiseNot("flags", BwFlags.HAS_COLOUR)
- Specified by:
bitwiseNot
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
bitwiseAll
public ExpressionList<T> bitwiseAll(String propertyName, long flags)
Description copied from interface:ExpressionList
Add expression for ALL of the given bit flags to be set.where().bitwiseAll("flags", BwFlags.HAS_BULK + BwFlags.HAS_COLOUR)
- Specified by:
bitwiseAll
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
bitwiseAnd
public ExpressionList<T> bitwiseAnd(String propertyName, long flags, long match)
Description copied from interface:ExpressionList
Add bitwise AND expression of the given bit flags to compare with the match/mask.// Flags Bulk + Size = Size // ... meaning Bulk is not set and Size is set long selectedFlags = BwFlags.HAS_BULK + BwFlags.HAS_SIZE; long mask = BwFlags.HAS_SIZE; // Only Size flag set where().bitwiseAnd("flags", selectedFlags, mask)
- Specified by:
bitwiseAnd
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property that holds the flags valueflags
- The flags we are looking for
-
eq
public ExpressionList<T> eq(String propertyName, Object value)
Description copied from interface:ExpressionList
Equal To - property is equal to a given value.- Specified by:
eq
in interfaceExpressionList<T>
-
eqOrNull
public ExpressionList<T> eqOrNull(String propertyName, Object value)
Description copied from interface:ExpressionList
Equal To or Null - property is equal to a given value or null.- Specified by:
eqOrNull
in interfaceExpressionList<T>
-
ieq
public ExpressionList<T> ieq(String propertyName, String value)
Description copied from interface:ExpressionList
Case Insensitive Equal To - property equal to the given value (typically using a lower() function to make it case insensitive).- Specified by:
ieq
in interfaceExpressionList<T>
-
ine
public ExpressionList<T> ine(String propertyName, String value)
Description copied from interface:ExpressionList
Case Insensitive Not Equal To - property not equal to the given value (typically using a lower() function to make it case insensitive).- Specified by:
ine
in interfaceExpressionList<T>
-
ne
public ExpressionList<T> ne(String propertyName, Object value)
Description copied from interface:ExpressionList
Not Equal To - property not equal to the given value.- Specified by:
ne
in interfaceExpressionList<T>
-
allEq
public ExpressionList<T> allEq(Map<String,Object> propertyMap)
Description copied from interface:ExpressionList
All Equal - Map containing property names and their values.Expression where all the property names in the map are equal to the corresponding value.
- Specified by:
allEq
in interfaceExpressionList<T>
- Parameters:
propertyMap
- a map keyed by property names.
-
and
public ExpressionList<T> and(Expression expOne, Expression expTwo)
Description copied from interface:ExpressionList
And - join two expressions with a logical and.- Specified by:
and
in interfaceExpressionList<T>
-
inRangeWith
public ExpressionList<T> inRangeWith(String lowProperty, String highProperty, Object value)
Description copied from interface:ExpressionList
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
- Specified by:
inRangeWith
in interfaceExpressionList<T>
-
inRange
public ExpressionList<T> inRange(String propertyName, Object value1, Object value2)
Description copied from interface:ExpressionList
In Range - property >= value1 and property < value2.Unlike Between inRange is "half open" and usually more useful for use with dates or timestamps.
- Specified by:
inRange
in interfaceExpressionList<T>
-
between
public ExpressionList<T> between(String propertyName, Object value1, Object value2)
Description copied from interface:ExpressionList
Between - property between the two given values.- Specified by:
between
in interfaceExpressionList<T>
-
betweenProperties
public ExpressionList<T> betweenProperties(String lowProperty, String highProperty, Object value)
Description copied from interface:ExpressionList
Between - value between the two properties.- Specified by:
betweenProperties
in interfaceExpressionList<T>
-
contains
public ExpressionList<T> contains(String propertyName, String value)
Description copied from interface:ExpressionList
Contains - property like %value%.- Specified by:
contains
in interfaceExpressionList<T>
-
endsWith
public ExpressionList<T> endsWith(String propertyName, String value)
Description copied from interface:ExpressionList
Ends With - property like %value.- Specified by:
endsWith
in interfaceExpressionList<T>
-
ge
public ExpressionList<T> ge(String propertyName, Object value)
Description copied from interface:ExpressionList
Greater Than or Equal to - property greater than or equal to the given value.- Specified by:
ge
in interfaceExpressionList<T>
-
gt
public ExpressionList<T> gt(String propertyName, Object value)
Description copied from interface:ExpressionList
Greater Than - property greater than the given value.- Specified by:
gt
in interfaceExpressionList<T>
-
gtOrNull
public ExpressionList<T> gtOrNull(String propertyName, Object value)
Description copied from interface:ExpressionList
Greater Than or Null - property greater than the given value or null.- Specified by:
gtOrNull
in interfaceExpressionList<T>
-
icontains
public ExpressionList<T> icontains(String propertyName, String value)
Description copied from interface:ExpressionList
Case insensitive Contains - property like %value%. Typically uses a lower() function to make the expression case insensitive.- Specified by:
icontains
in interfaceExpressionList<T>
-
idIn
public ExpressionList<T> idIn(Object... idValues)
Description copied from interface:ExpressionList
Id IN a list of id values.- Specified by:
idIn
in interfaceExpressionList<T>
-
idIn
public ExpressionList<T> idIn(Collection<?> idCollection)
Description copied from interface:ExpressionList
Id IN a collection of id values.- Specified by:
idIn
in interfaceExpressionList<T>
-
idEq
public ExpressionList<T> idEq(Object value)
Description copied from interface:ExpressionList
Id Equal to - ID property is equal to the value.- Specified by:
idEq
in interfaceExpressionList<T>
-
iendsWith
public ExpressionList<T> iendsWith(String propertyName, String value)
Description copied from interface:ExpressionList
Case insensitive Ends With - property like %value. Typically uses a lower() function to make the expression case insensitive.- Specified by:
iendsWith
in interfaceExpressionList<T>
-
ilike
public ExpressionList<T> ilike(String propertyName, String value)
Description copied from interface:ExpressionList
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.- Specified by:
ilike
in interfaceExpressionList<T>
-
inPairs
public ExpressionList<T> inPairs(Pairs pairs)
Description copied from interface:ExpressionList
In expression using pairs of value objects.- Specified by:
inPairs
in interfaceExpressionList<T>
-
in
public ExpressionList<T> in(String propertyName, Query<?> subQuery)
Description copied from interface:ExpressionList
In - using a subQuery.- Specified by:
in
in interfaceExpressionList<T>
-
in
public ExpressionList<T> in(String propertyName, Collection<?> values)
Description copied from interface:ExpressionList
In - property has a value in the collection of values.- Specified by:
in
in interfaceExpressionList<T>
-
inOrEmpty
public ExpressionList<T> inOrEmpty(String propertyName, Collection<?> values)
Description copied from interface:ExpressionList
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();
- Specified by:
inOrEmpty
in interfaceExpressionList<T>
-
in
public ExpressionList<T> in(String propertyName, Object... values)
Description copied from interface:ExpressionList
In - property has a value in the array of values.- Specified by:
in
in interfaceExpressionList<T>
-
notIn
public ExpressionList<T> notIn(String propertyName, Object... values)
Description copied from interface:ExpressionList
Not In - property has a value in the array of values.- Specified by:
notIn
in interfaceExpressionList<T>
-
notIn
public ExpressionList<T> notIn(String propertyName, Collection<?> values)
Description copied from interface:ExpressionList
Not In - property has a value in the collection of values.- Specified by:
notIn
in interfaceExpressionList<T>
-
notIn
public ExpressionList<T> notIn(String propertyName, Query<?> subQuery)
Description copied from interface:ExpressionList
Not In - using a subQuery.- Specified by:
notIn
in interfaceExpressionList<T>
-
isEmpty
public ExpressionList<T> isEmpty(String propertyName)
Description copied from interface:ExpressionList
Is empty expression for collection properties.- Specified by:
isEmpty
in interfaceExpressionList<T>
-
isNotEmpty
public ExpressionList<T> isNotEmpty(String propertyName)
Description copied from interface:ExpressionList
Is not empty expression for collection properties.- Specified by:
isNotEmpty
in interfaceExpressionList<T>
-
exists
public ExpressionList<T> exists(Query<?> subQuery)
Description copied from interface:ExpressionList
Exists expression- Specified by:
exists
in interfaceExpressionList<T>
-
notExists
public ExpressionList<T> notExists(Query<?> subQuery)
Description copied from interface:ExpressionList
Not exists expression- Specified by:
notExists
in interfaceExpressionList<T>
-
isNotNull
public ExpressionList<T> isNotNull(String propertyName)
Description copied from interface:ExpressionList
Is Not Null - property is not null.- Specified by:
isNotNull
in interfaceExpressionList<T>
-
isNull
public ExpressionList<T> isNull(String propertyName)
Description copied from interface:ExpressionList
Is Null - property is null.- Specified by:
isNull
in interfaceExpressionList<T>
-
istartsWith
public ExpressionList<T> istartsWith(String propertyName, String value)
Description copied from interface:ExpressionList
Case insensitive Starts With - property like value%. Typically uses a lower() function to make the expression case insensitive.- Specified by:
istartsWith
in interfaceExpressionList<T>
-
le
public ExpressionList<T> le(String propertyName, Object value)
Description copied from interface:ExpressionList
Less Than or Equal to - property less than or equal to the given value.- Specified by:
le
in interfaceExpressionList<T>
-
exampleLike
public ExpressionList<T> exampleLike(Object example)
Description copied from interface:ExpressionList
A "Query By Example" type of expression.Pass in an example entity and for each non-null scalar properties an expression is added.
By Default this case sensitive, will ignore numeric zero values and will use a Like for string values (you must put in your own wildcards).
To get control over the options you can create an ExampleExpression and set those options such as case insensitive etc.
// create an example bean and set the properties // with the query parameters you want Customer example = new Customer(); example.setName("Rob%"); example.setNotes("%something%"); List<Customer> list = DB.find(Customer.class) .where().exampleLike(example) .findList();
Similarly you can create an ExampleExpression
Customer example = new Customer(); example.setName("Rob%"); example.setNotes("%something%"); // create a ExampleExpression with more control ExampleExpression qbe = new ExampleExpression(example, true, LikeType.EQUAL_TO).includeZeros(); List<Customer> list = DB.find(Customer.class).where().add(qbe).findList();
- Specified by:
exampleLike
in interfaceExpressionList<T>
-
iexampleLike
public ExpressionList<T> iexampleLike(Object example)
Description copied from interface:ExpressionList
Case insensitive version ofExpressionList.exampleLike(Object)
- Specified by:
iexampleLike
in interfaceExpressionList<T>
-
like
public ExpressionList<T> like(String propertyName, String value)
Description copied from interface:ExpressionList
Like - property like value where the value contains the SQL wild card characters % (percentage) and _ (underscore).- Specified by:
like
in interfaceExpressionList<T>
-
lt
public ExpressionList<T> lt(String propertyName, Object value)
Description copied from interface:ExpressionList
Less Than - property less than the given value.- Specified by:
lt
in interfaceExpressionList<T>
-
ltOrNull
public ExpressionList<T> ltOrNull(String propertyName, Object value)
Description copied from interface:ExpressionList
Less Than or Null - property less than the given value or null.- Specified by:
ltOrNull
in interfaceExpressionList<T>
-
not
public ExpressionList<T> not(Expression exp)
Description copied from interface:ExpressionList
Negate the expression (prefix it with NOT).- Specified by:
not
in interfaceExpressionList<T>
-
or
public ExpressionList<T> or(Expression expOne, Expression expTwo)
Description copied from interface:ExpressionList
Or - join two expressions with a logical or.- Specified by:
or
in interfaceExpressionList<T>
-
arrayContains
public ExpressionList<T> arrayContains(String propertyName, Object... elementValue)
Description copied from interface:ExpressionList
Array property contains entries with the given values.- Specified by:
arrayContains
in interfaceExpressionList<T>
-
arrayNotContains
public ExpressionList<T> arrayNotContains(String propertyName, Object... values)
Description copied from interface:ExpressionList
Array does not contain the given values.Array support is effectively limited to Postgres at this time.
- Specified by:
arrayNotContains
in interfaceExpressionList<T>
-
arrayIsEmpty
public ExpressionList<T> arrayIsEmpty(String propertyName)
Description copied from interface:ExpressionList
Array is empty - for the given array property.Array support is effectively limited to Postgres at this time.
- Specified by:
arrayIsEmpty
in interfaceExpressionList<T>
-
arrayIsNotEmpty
public ExpressionList<T> arrayIsNotEmpty(String propertyName)
Description copied from interface:ExpressionList
Array is not empty - for the given array property.Array support is effectively limited to Postgres at this time.
- Specified by:
arrayIsNotEmpty
in interfaceExpressionList<T>
-
raw
public ExpressionList<T> raw(String raw, Object value)
Description copied from interface:ExpressionList
Add raw expression with a single parameter.The raw expression should contain a single ? at the location of the parameter.
When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.
Example:
// use a database function raw("add_days(orderDate, 10) < ?", someDate)
Subquery example:
.raw("t0.customer_id in (select customer_id from customer_group where group_id = any(?::uuid[]))", groupIds)
- Specified by:
raw
in interfaceExpressionList<T>
-
raw
public ExpressionList<T> raw(String raw, Object... values)
Description copied from interface:ExpressionList
Add raw expression with an array of parameters.The raw expression should contain the same number of ? as there are parameters.
When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.
- Specified by:
raw
in interfaceExpressionList<T>
-
raw
public ExpressionList<T> raw(String raw)
Description copied from interface:ExpressionList
Add raw expression with no parameters.When properties in the clause are fully qualified as table-column names then they are not translated. logical property name names (not fully qualified) will still be translated to their physical name.
raw("orderQty < shipQty")
Subquery example:
.raw("t0.customer_id in (select customer_id from customer_group where group_id = any(?::uuid[]))", groupIds)
- Specified by:
raw
in interfaceExpressionList<T>
-
rawOrEmpty
public ExpressionList<T> rawOrEmpty(String raw, Collection<?> values)
Description copied from interface:ExpressionList
Only add the raw expression if the values is not null or empty.This is a pure convenience expression to make it nicer to deal with the pattern where we use raw() expression with a subquery and only want to add the subquery predicate when the collection of values is not empty.
Without inOrEmpty()
query.where() // add some predicates .eq("status", Status.NEW); // common pattern - we can use rawOrEmpty() instead if (orderIds != null && !orderIds.isEmpty()) { query.where().raw("t0.customer_id in (select o.customer_id from orders o where o.id in (?1))", orderIds); } query.findList();
Using rawOrEmpty()
Note that in the example below we use the?1
bind parameter to get "parameter expansion" for each element in the collection.query.where() .eq("status", Status.NEW) // only add the expression if orderIds is not empty .rawOrEmpty("t0.customer_id in (select o.customer_id from orders o where o.id in (?1))", orderIds); .findList();
Postgres ANY
With Postgres we would often use the SQLANY
expression and array parameter binding rather thanIN
.query.where() .eq("status", Status.NEW) .rawOrEmpty("t0.customer_id in (select o.customer_id from orders o where o.id = any(?))", orderIds); .findList();
Note that we need to cast the Postgres array for UUID types like:
" ... = any(?::uuid[])"
- Specified by:
rawOrEmpty
in interfaceExpressionList<T>
- Parameters:
raw
- The raw expression that is typically a subqueryvalues
- The values which is typically a list or set of id values.
-
startsWith
public ExpressionList<T> startsWith(String propertyName, String value)
Description copied from interface:ExpressionList
Starts With - property like value%.- Specified by:
startsWith
in interfaceExpressionList<T>
-
match
public ExpressionList<T> match(String propertyName, String search)
Description copied from interface:ExpressionList
Add a match expression.- Specified by:
match
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property name for the matchsearch
- The search value
-
match
public ExpressionList<T> match(String propertyName, String search, Match options)
Description copied from interface:ExpressionList
Add a match expression with options.- Specified by:
match
in interfaceExpressionList<T>
- Parameters:
propertyName
- The property name for the matchsearch
- The search value
-
multiMatch
public ExpressionList<T> multiMatch(String query, String... fields)
Description copied from interface:ExpressionList
Add a multi-match expression.- Specified by:
multiMatch
in interfaceExpressionList<T>
-
multiMatch
public ExpressionList<T> multiMatch(String query, MultiMatch options)
Description copied from interface:ExpressionList
Add a multi-match expression using options.- Specified by:
multiMatch
in interfaceExpressionList<T>
-
textSimple
public ExpressionList<T> textSimple(String search, TextSimple options)
Description copied from interface:ExpressionList
Add a simple query string expression.- Specified by:
textSimple
in interfaceExpressionList<T>
-
textQueryString
public ExpressionList<T> textQueryString(String search, TextQueryString options)
Description copied from interface:ExpressionList
Add a query string expression.- Specified by:
textQueryString
in interfaceExpressionList<T>
-
textCommonTerms
public ExpressionList<T> textCommonTerms(String search, TextCommonTerms options)
Description copied from interface:ExpressionList
Add common terms expression.- Specified by:
textCommonTerms
in interfaceExpressionList<T>
-
endJunction
public ExpressionList<T> endJunction()
Description copied from interface:ExpressionList
End a junction returning the parent expression list.Ends a and(), or(), not(), must(), mustNot() or should() junction such that you get the parent expression.
Alternatively you can always use where() to return the top level expression list.
- Specified by:
endJunction
in interfaceExpressionList<T>
-
endAnd
public ExpressionList<T> endAnd()
Description copied from interface:ExpressionList
End a AND junction - synonym for endJunction().- Specified by:
endAnd
in interfaceExpressionList<T>
-
endOr
public ExpressionList<T> endOr()
Description copied from interface:ExpressionList
End a AND junction - synonym for endJunction().- Specified by:
endOr
in interfaceExpressionList<T>
-
endNot
public ExpressionList<T> endNot()
Description copied from interface:ExpressionList
End a NOT junction - synonym for endJunction().- Specified by:
endNot
in interfaceExpressionList<T>
-
and
public Junction<T> and()
Description copied from interface:ExpressionList
Start a list of expressions that will be joined by AND's returning the expression list the expressions are added to.This is exactly the same as conjunction();
Use endAnd() or endJunction() to end the AND junction.
Note that a where() clause defaults to an AND junction so typically you only explicitly need to use the and() junction when it is nested inside an or() or not() junction.
// Example: Nested and() .where() .or() .and() // nested and .startsWith("name", "r") .eq("anniversary", onAfter) .endAnd() .and() .eq("status", Customer.Status.ACTIVE) .gt("id", 0) .endAnd() .order().asc("name") .findList();
- Specified by:
and
in interfaceExpressionList<T>
-
or
public Junction<T> or()
Description copied from interface:ExpressionList
Return a list of expressions that will be joined by OR's. This is exactly the same as disjunction();Use endOr() or endJunction() to end the OR junction.
// Example: (status active OR anniversary is null) .where() .or() .eq("status", Customer.Status.ACTIVE) .isNull("anniversary") .order().asc("name") .findList();
// Example: Use or() to join // two nested and() expressions .where() .or() .and() .startsWith("name", "r") .eq("anniversary", onAfter) .endAnd() .and() .eq("status", Customer.Status.ACTIVE) .gt("id", 0) .endAnd() .order().asc("name") .findList();
- Specified by:
or
in interfaceExpressionList<T>
-
not
public Junction<T> not()
Description copied from interface:ExpressionList
Return a list of expressions that will be wrapped by NOT.Use endNot() or endJunction() to end expressions being added to the NOT expression list.
.where() .not() .gt("id", 1) .eq("anniversary", onAfter) .endNot()
// Example: nested not() .where() .eq("status", Customer.Status.ACTIVE) .not() .gt("id", 1) .eq("anniversary", onAfter) .endNot() .order() .asc("name") .findList();
- Specified by:
not
in interfaceExpressionList<T>
-
conjunction
public Junction<T> conjunction()
Description copied from interface:ExpressionList
Start (and return) a list of expressions that will be joined by AND's.This is the same as and().
- Specified by:
conjunction
in interfaceExpressionList<T>
-
disjunction
public Junction<T> disjunction()
Description copied from interface:ExpressionList
Start (and return) a list of expressions that will be joined by OR's.This is the same as or().
- Specified by:
disjunction
in interfaceExpressionList<T>
-
must
public Junction<T> must()
Description copied from interface:ExpressionList
Start a list of expressions that will be joined by MUST.This automatically makes the query a useDocStore(true) query that will execute against the document store (ElasticSearch etc).
This is logically similar to and().
- Specified by:
must
in interfaceExpressionList<T>
-
should
public Junction<T> should()
Description copied from interface:ExpressionList
Start a list of expressions that will be joined by SHOULD.This automatically makes the query a useDocStore(true) query that will execute against the document store (ElasticSearch etc).
This is logically similar to or().
- Specified by:
should
in interfaceExpressionList<T>
-
mustNot
public Junction<T> mustNot()
Description copied from interface:ExpressionList
Start a list of expressions that will be joined by MUST NOT.This automatically makes the query a useDocStore(true) query that will execute against the document store (ElasticSearch etc).
This is logically similar to not().
- Specified by:
mustNot
in interfaceExpressionList<T>
-
nestedPath
public String nestedPath(BeanDescriptor<?> desc)
Description copied from interface:SpiExpression
Return the nested path for this expression.- Specified by:
nestedPath
in interfaceSpiExpression
-
setAllDocNested
public void setAllDocNested(String allDocNestedPath)
Set the nested path that all contained expressions share.
-
setUnderlying
public void setUnderlying(List<SpiExpression> groupedByNesting)
Replace the underlying expression list with one organised by nested path.
-
prepareDocNested
public void prepareDocNested(BeanDescriptor<T> beanDescriptor)
Prepare expressions for document store nested path handling.
-
-