Interface Query
- All Known Subinterfaces:
RelationQuery
- All Known Implementing Classes:
AbstractHibernateQueryAdapter
,AbstractOrderableQuery
,AbstractRelationQueryAdapter
,EmptyQuery
,HibernateQueryAdapter
,ToManyRelationQueryAdapter
,ToOneRelationQueryAdapter
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionappendOrder
(Ordering order) Append the givenOrdering
policy to the existing ordering policy of this query.int
count()
Currently badly implemented! Count the results.execute()
Execute the query inQuery.Mode.LAZY
mode using the default limit.execute
(int limit) Deprecated.execute
(int limit, Query.Mode mode) Deprecated.execute
(Pagination pagination) Execute the query using the specified pagination parameters inQuery.Mode.LAZY
mode.execute
(Pagination pagination, Query.Mode mode) Execute the query using the specified pagination parameters in the specifiedQuery.Mode
.execute
(Query.Mode mode) Execute the query in the specifiedQuery.Mode
using the default limit.Executes and returns the first selected Entity by this query, or throws.@Nullable Entity
Executes and returns the first selected Entity by this query, or null if none.default PrimaryKey[]
getKeys()
Returns pks with no limitdefault PrimaryKey[]
getKeys
(Pagination pagination) Returns pks within given paginationGet the entity manager.Executes and returns the single selected Entity by this query, or throws.getOnlyResult
(LockMode lockMode) @Nullable Entity
Executes and returns the single selected Entity by this query, or null if none, or throws.@Nullable Entity
getOnlyResultOrNull
(LockMode lockMode) Get a reference to theOrdering
policy of this query.boolean
Check whether this query has an ordering policy already.prependOrder
(Ordering order) Prepend the givenOrdering
policy to the existing ordering policy of this query.void
setParameter
(String name, Object value) Set a parameter for the query.Deprecated.usegetOnlyResult()
@Nullable Entity
Deprecated.usegetOnlyResultOrNull()
()}Replace theOrdering
policy of this query with the given ordering policy.
-
Method Details
-
setParameter
Set a parameter for the query.- Parameters:
name
- The name of the parametervalue
- The value of the parameter in the correct data type.- Throws:
PersistException
- If the parameter cannot be set (invalid name, invalid value)
-
getOrdering
Ordering getOrdering()Get a reference to theOrdering
policy of this query. If there currently is no ordering policy, one will be created.- Returns:
- The ordering policy of this query.
-
hasOrdering
boolean hasOrdering()Check whether this query has an ordering policy already.- Returns:
true
, if this query has an ordering policy with at least one rule,false
if none or one without rules (which may mean that getOrdering() will make one up on the fly).
-
withOrder
Replace theOrdering
policy of this query with the given ordering policy. If the given ordering policy is null or empty, it will be ignored and the existing ordering policy of the query will be preserved.- Returns:
- this query.
-
prependOrder
Prepend the givenOrdering
policy to the existing ordering policy of this query.- Parameters:
order
- the ordering policy to prepend.- Returns:
- this query.
-
appendOrder
Append the givenOrdering
policy to the existing ordering policy of this query.- Parameters:
order
- the ordering policy to append.- Returns:
- this query.
-
getKeys
Returns pks with no limit- Returns:
- PKs of result entities.
-
getKeys
Returns pks within given pagination- Parameters:
pagination
- Limit and offset of result- Returns:
- PKs of result entities.
-
execute
Execute the query inQuery.Mode.LAZY
mode using the default limit.- Returns:
- The result of the query. To further process it use the
EntityLists
class. - Throws:
PersistException
- If an error occurs
-
execute
Execute the query in the specifiedQuery.Mode
using the default limit.- Parameters:
mode
- The query mode.- Returns:
- The result of the query.
- Throws:
PersistException
- If an error occurs
-
execute
Deprecated.Execute the query using the specified limit inQuery.Mode.LAZY
mode.- Parameters:
limit
- The maximum number of results, see class header (really).- Returns:
- The result of the query.
- Throws:
PersistException
- If an error occurred.
-
execute
Deprecated.Execute the query using the specified limit in the specifiedQuery.Mode
.- Parameters:
limit
- The maximum number of results, see class header (really).mode
- The mode.- Returns:
- The result of the query.
- Throws:
PersistException
- If an error occurred.
-
execute
Execute the query using the specified pagination parameters inQuery.Mode.LAZY
mode.- Parameters:
pagination
- The offset and limit of the query.- Returns:
- The result of the query.
-
execute
Execute the query using the specified pagination parameters in the specifiedQuery.Mode
.- Parameters:
pagination
- The offset and limit of the query.mode
- The mode.- Returns:
- The result of the query.
-
getOnlyResult
Entity getOnlyResult()Executes and returns the single selected Entity by this query, or throws.- Returns:
- The single selected Entity.
- Throws:
PermanentPersistException
- If the query does not select exactly one Entity. Note that it does not matter if the model is to-1 or to-many.- See Also:
-
getOnlyResult
-
uniqueResult
Deprecated.usegetOnlyResult()
Executes and returns the single selected Entity by this query, or throws.- Returns:
- The single selected Entity.
- Throws:
PermanentPersistException
- If the query does not select exactly one Entity. Note that it does not matter if the model is to-1 or to-many.PersistException
- See Also:
-
getOnlyResultOrNull
Executes and returns the single selected Entity by this query, or null if none, or throws.- Returns:
- The single selected Entity, or
null
if none. - Throws:
PermanentPersistException
- If the query selects more than one Entity. Note that it does not matter if the model is to-1 or to-many.- See Also:
-
getOnlyResultOrNull
-
uniqueResultOrNull
Deprecated.usegetOnlyResultOrNull()
()}Executes and returns the single selected Entity by this query, or null if none, or throws.- Returns:
- The single selected Entity, or
null
if none. - Throws:
PermanentPersistException
- If the query selects more than one Entity. Note that it does not matter if the model is to-1 or to-many.PersistException
- See Also:
-
firstResult
Executes and returns the first selected Entity by this query, or throws.- Returns:
- The first selected Entity.
- Throws:
PermanentPersistException
- If the query does not select at least one Entity.PersistException
- See Also:
-
firstResultOrNull
Executes and returns the first selected Entity by this query, or null if none.- Returns:
- The first selected Entity, or
null
if none. - Throws:
PersistException
- If an error occurred.- See Also:
-
count
Currently badly implemented! Count the results.WARNING: This method does not behave as "SELECT count()" in SQL does! In fact it is temporarily implemented as a chaining of execute().size() only. No query modification is done etc. ALSO, the default query limit is used and thus if there would be more records, only the default limit is returned. The impl may be rewritten to be what one would expect; until then users may only use this method if they can live with today's limits: small counts.
Speed of "SELECT count()" greatly depends on the underlying db table impl. An example are the two MySQL table types MyISAM and InnoDB. A query-less count on the former returns instantly because it keeps track of the number, whereas the latter needs to iterate over all records (at least in case of non-fixed length record tables) and can take minutes depending on the size.
- Returns:
- The count.
- Throws:
PersistException
- If an error occurs.
-
getManager
EntityManager getManager()Get the entity manager.- Returns:
- The entity manager.
-
toQueryDefinition
QueryDefinition toQueryDefinition()
-
execute(Pagination)