Interface QueryEnhancer
- All Known Implementing Classes:
JSqlParserQueryEnhancer
public interface QueryEnhancer
This interface describes the API for enhancing a given Query. Query enhancers understand the syntax of the query and
can introspect queries to determine aliases and projections. Enhancers can also rewrite queries to apply sorting and
create count queries if the underlying query is a
SELECT query.- Since:
- 2.7
- Author:
- Diego Krupitza, Greg Turnquist, Mark Paluch
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface to describe the information needed to rewrite a query. -
Method Summary
Modifier and TypeMethodDescriptionstatic QueryEnhancercreate(DeclaredQuery query) Creates a newQueryEnhancerfor aDeclaredQuery.createCountQueryFor(@Nullable String countProjection) Creates a count projected query from the given original query using the providedcountProjection.@Nullable StringResolves the primary alias for the entity to be retrieved from the given JPA query.Returns the projection part of the query, i.e. everything betweenselectandfrom.getQuery()Gets the query we want to use for enhancements.booleanReturns whether the given JPQL query contains a constructor expression.default booleanrewrite(QueryEnhancer.QueryRewriteInformation rewriteInformation) Rewrite the query to include sorting and applyReturnedTypecustomizations.
-
Method Details
-
create
Creates a newQueryEnhancerfor aDeclaredQuery. Convenience method forQueryEnhancerFactory.create(QueryProvider).- Parameters:
query- the query to be enhanced.- Returns:
- the new
QueryEnhancer. - Since:
- 4.0
-
isSelectQuery
default boolean isSelectQuery()- Returns:
- whether the underlying query is a SELECT query.
- Since:
- 4.0
-
hasConstructorExpression
boolean hasConstructorExpression()Returns whether the given JPQL query contains a constructor expression.- Returns:
- whether the given JPQL query contains a constructor expression.
-
detectAlias
@Nullable String detectAlias()Resolves the primary alias for the entity to be retrieved from the given JPA query.- Returns:
- can return null.
-
getProjection
String getProjection()Returns the projection part of the query, i.e. everything betweenselectandfrom.- Returns:
- the projection part of the query.
-
getQuery
QueryProvider getQuery()Gets the query we want to use for enhancements.- Returns:
- non-null
DeclaredQuerythat wraps the query.
-
rewrite
Rewrite the query to include sorting and applyReturnedTypecustomizations.- Parameters:
rewriteInformation- the rewrite information to apply.- Returns:
- the modified query string.
- Throws:
IllegalStateException- if the underlying query is not aSELECTquery.- Since:
- 4.0
-
createCountQueryFor
Creates a count projected query from the given original query using the providedcountProjection.- Parameters:
countProjection- may be null.- Returns:
- a query String to be used a count query for pagination. Guaranteed to be not null.
- Throws:
IllegalStateException- if the underlying query is not aSELECTquery.
-