Interface EntityQuery
- All Superinterfaces:
ParametrizedQuery, QueryProvider
An extension to
ParametrizedQuery exposing query information about its inner structure such as whether
constructor expressions (JPQL) are used or the default projection is used.
Entity Queries support derivation of count queries from the original query. They
also can be used to rewrite the query using sorting and projection selection.
- Since:
- 4.0
- Author:
- Jens Schauder, Diego Krupitza
-
Method Summary
Modifier and TypeMethodDescriptionstatic EntityQuerycreate(DeclaredQuery query, QueryEnhancerSelector selector) deriveCountQuery(@Nullable String countQueryProjection) Creates a new IntrospectedQuery representing a count query, i.e. a query returning the number of rows to be expected from the original query, either derived from the query wrapped by this instance or from the information passed as arguments.<T extends @Nullable Object>
TdoWithEnhancer(Function<QueryEnhancer, T> function) Apply aFunctionto the query enhancer used by this query.getQuery()booleanReturns whether the query is using a constructor expression.booleanReturns whether the query uses the default projection, i.e. returns the main alias defined for the query.booleanisNative()rewrite(QueryEnhancer.QueryRewriteInformation rewriteInformation) Rewrite the query using the givenQueryEnhancer.QueryRewriteInformationinto a sorted query or using a different projection.default booleanMethods inherited from interface ParametrizedQuery
getParameterBindings, hasNamedParameter, hasParameterBindings, usesJdbcStyleParametersMethods inherited from interface QueryProvider
getQueryString
-
Method Details
-
create
- Parameters:
query- must not be null.selector- must not be null.- Returns:
- a new
EntityQuery.
-
doWithEnhancer
Apply aFunctionto the query enhancer used by this query.- Type Parameters:
T-- Parameters:
function- the callback function.- Returns:
-
hasConstructorExpression
boolean hasConstructorExpression()Returns whether the query is using a constructor expression.- Since:
- 1.10
-
isNative
boolean isNative()- Returns:
- whether the underlying query has at least one named parameter.
-
isDefaultProjection
boolean isDefaultProjection()Returns whether the query uses the default projection, i.e. returns the main alias defined for the query. -
usesPaging
default boolean usesPaging()- Returns:
- whether paging is implemented in the query itself, e.g. using SpEL expressions.
- Since:
- 2.0.6
-
getQuery
PreprocessedQuery getQuery() -
deriveCountQuery
Creates a new IntrospectedQuery representing a count query, i.e. a query returning the number of rows to be expected from the original query, either derived from the query wrapped by this instance or from the information passed as arguments.- Parameters:
countQueryProjection- an optional return type for the query.- Returns:
- a new IntrospectedQuery instance.
-
rewrite
Rewrite the query using the givenQueryEnhancer.QueryRewriteInformationinto a sorted query or using a different projection. The rewritten query retains parameter binding characteristics.- Parameters:
rewriteInformation- query rewrite information (sorting, projection) to use.- Returns:
- the rewritten query.
-