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
  • Method Details

    • create

      static QueryEnhancer create(DeclaredQuery query)
      Creates a new QueryEnhancer for a DeclaredQuery. Convenience method for QueryEnhancerFactory.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 between select and from.
      Returns:
      the projection part of the query.
    • getQuery

      QueryProvider getQuery()
      Gets the query we want to use for enhancements.
      Returns:
      non-null DeclaredQuery that wraps the query.
    • rewrite

      String rewrite(QueryEnhancer.QueryRewriteInformation rewriteInformation)
      Rewrite the query to include sorting and apply ReturnedType customizations.
      Parameters:
      rewriteInformation - the rewrite information to apply.
      Returns:
      the modified query string.
      Throws:
      IllegalStateException - if the underlying query is not a SELECT query.
      Since:
      4.0
    • createCountQueryFor

      String createCountQueryFor(@Nullable String countProjection)
      Creates a count projected query from the given original query using the provided countProjection.
      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 a SELECT query.