Class PreprocessedQuery

java.lang.Object
org.springframework.data.jpa.repository.query.PreprocessedQuery
All Implemented Interfaces:
DeclaredQuery, QueryProvider

public final class PreprocessedQuery extends Object implements DeclaredQuery
A pre-parsed query implementing DeclaredQuery providing information about parameter bindings.

Query-preprocessing transforms queries using Spring Data-specific syntax such as query templating, extended LIKE syntax and usage of value expressions into a syntax that is valid for JPA queries (JPQL and native).

Preprocessing consists of parsing and rewriting so that no extension elements interfere with downstream parsers. However, pre-processing is a lossy procedure because the resulting query string only contains parameter binding markers and so the original query cannot be restored. Any query derivation must align its parameter bindings to ensure the derived query uses the same binding semantics instead of plain parameters. See ParameterBinding.isCompatibleWith(ParameterBinding) for further reference.

Since:
4.0
Author:
Christoph Strobl, Mark Paluch
  • Method Details

    • parse

      public static PreprocessedQuery parse(DeclaredQuery declaredQuery)
      Parse a query into its parametrized form by identifying anonymous, named, indexed and SpEL parameters. Query parsing applies special treatment to IN and LIKE parameter bindings.
      Parameters:
      declaredQuery - the source query to parse.
      Returns:
      a parsed PreprocessedQuery.
    • getQueryString

      public String getQueryString()
      Description copied from interface: QueryProvider
      Return the query string.
      Specified by:
      getQueryString in interface QueryProvider
      Returns:
      the query string.
    • isNative

      public boolean isNative()
      Description copied from interface: DeclaredQuery
      Return whether the query is a native query of not.
      Specified by:
      isNative in interface DeclaredQuery
      Returns:
      true if native query; false if it is a JPQL query.
    • containsPageableInSpel

      public boolean containsPageableInSpel()
    • getBindings

      public List<ParameterBinding> getBindings()
    • rewrite

      public PreprocessedQuery rewrite(String newQueryString)
      Derive a query (typically a count query) from the given query string. We need to copy expression bindings from the declared to the derived query as JPQL query derivation only sees JPA parameter markers and not the original expressions anymore.
      Specified by:
      rewrite in interface DeclaredQuery
      Parameters:
      newQueryString - the new query string.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object