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 EntityQuery
create
(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 aFunction
to the query enhancer used by this query.boolean
Returns whether the query is using a constructor expression.boolean
Returns whether the query uses the default projection, i.e. returns the main alias defined for the query.boolean
isNative()
rewrite
(QueryEnhancer.QueryRewriteInformation rewriteInformation) Rewrite the query using the givenQueryEnhancer.QueryRewriteInformation
into a sorted query or using a different projection.default boolean
Methods inherited from interface org.springframework.data.jpa.repository.query.ParametrizedQuery
getParameterBindings, hasNamedParameter, hasParameterBindings, usesJdbcStyleParameters
Methods inherited from interface org.springframework.data.jpa.repository.query.QueryProvider
getQueryString
-
Method Details
-
create
- Parameters:
query
- must not be null.selector
- must not be null.- Returns:
- a new
EntityQuery
.
-
doWithEnhancer
Apply aFunction
to 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
-
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.QueryRewriteInformation
into 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.
-