Interface QueryEnhancer
- All Known Implementing Classes:
DefaultQueryEnhancer
,JSqlParserQueryEnhancer
public interface QueryEnhancer
This interface describes the API for enhancing a given Query.
- Since:
- 2.7.0
- Author:
- Diego Krupitza, Greg Turnquist
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
applySorting
(org.springframework.data.domain.Sort sort) Adds order by clause to the JPQL query.applySorting
(org.springframework.data.domain.Sort sort, String alias) Adds order by clause to the JPQL query.default String
Creates a count projected query from the given original query.createCountQueryFor
(String countProjection) Creates a count projected query from the given original query using the providedcountProjection
.Resolves the alias for the entity to be retrieved from the given JPA query.Returns the projection part of the query, i.e. everything betweenselect
andfrom
.org.springframework.data.jpa.repository.query.DeclaredQuery
getQuery()
Gets the query we want to use for enhancements.default boolean
Returns whether the given JPQL query contains a constructor expression.
-
Method Details
-
applySorting
Adds order by clause to the JPQL query. Uses the first alias to bind the sorting property to.- Parameters:
sort
- the sort specification to apply.- Returns:
- the modified query string.
-
applySorting
Adds order by clause to the JPQL query.- Parameters:
sort
- the sort specification to apply.alias
- the alias to be used in the order by clause. May be null or empty.- Returns:
- the modified query string.
-
detectAlias
Resolves the alias for the entity to be retrieved from the given JPA query.- Returns:
- Might return null.
-
createCountQueryFor
Creates a count projected query from the given original query.- Returns:
- Guaranteed to be not null.
-
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.
-
hasConstructorExpression
default boolean hasConstructorExpression()Returns whether the given JPQL query contains a constructor expression.- Returns:
- whether the given JPQL query contains a constructor expression.
-
getProjection
String getProjection()Returns the projection part of the query, i.e. everything betweenselect
andfrom
.- Returns:
- the projection part of the query.
-
getJoinAliases
-
getQuery
org.springframework.data.jpa.repository.query.DeclaredQuery getQuery()Gets the query we want to use for enhancements.- Returns:
- non-null
DeclaredQuery
that wraps the query
-