Interface QueryRewriter

All Known Implementing Classes:
DelegatingQueryRewriter, QueryRewriter.IdentityQueryRewriter
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface QueryRewriter
Callback to rewrite a query and apply sorting and pagination settings that cannot be applied based on a regularly detectable scheme.

The underlying the query is the one right before it is used for query object creation, so everything that Spring Data and tools intends to do has been done. You can customize the query to apply final changes. Rewriting can only make use of already existing contextual data. That is, adding or replacing query text or reuse of bound parameters. Query rewriting must not add additional bindable parameters as these cannot be materialized.

Since:
3.0
Author:
Greg Turnquist, Mark Paluch
See Also:
  • EntityManager.createQuery(java.lang.String)
  • EntityManager.createNativeQuery(java.lang.String)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    A QueryRewriter that doesn't change the query.
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    rewrite(String query, org.springframework.data.domain.Pageable pageRequest)
    Rewrite the assembled query with the given Pageable.
    rewrite(String query, org.springframework.data.domain.Sort sort)
    Rewrite the assembled query with the given Sort.
  • Method Details

    • rewrite

      String rewrite(String query, org.springframework.data.domain.Sort sort)
      Rewrite the assembled query with the given Sort.

      WARNING: No checks are performed before the transformed query is passed to the EntityManager.

      Parameters:
      query - the assembled query.
      sort - current Sort settings provided by the method, or Sort.unsorted()} if there are none.
      Returns:
      the query to be used with the EntityManager.
    • rewrite

      default String rewrite(String query, org.springframework.data.domain.Pageable pageRequest)
      Rewrite the assembled query with the given Pageable.
      Parameters:
      query - the assembled query.
      pageRequest - current Pageable settings provided by the method, or Pageable.unpaged() if not paged.
      Returns:
      the query to be used with the EntityManager.