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 Type
    Method
    Description
    default String
    Adds order by clause to the JPQL query.
    applySorting(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 provided countProjection.
    Resolves the alias for the entity to be retrieved from the given JPA query.
     
    Returns the projection part of the query, i.e. everything between select and from.
    org.springframework.data.jpa.repository.query.DeclaredQuery
    Gets the query we want to use for enhancements.
    default boolean
    Returns whether the given JPQL query contains a constructor expression.
  • Method Details

    • applySorting

      default String applySorting(Sort sort)
      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

      String applySorting(Sort sort, @Nullable String alias)
      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

      @Nullable String detectAlias()
      Resolves the alias for the entity to be retrieved from the given JPA query.
      Returns:
      Might return null.
    • createCountQueryFor

      default String createCountQueryFor()
      Creates a count projected query from the given original query.
      Returns:
      Guaranteed to be not null.
    • 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.
    • 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 between select and from.
      Returns:
      the projection part of the query.
    • getJoinAliases

      Set<String> 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