Interface QuerySpecification<T>

Type Parameters:
T - The entity root type

public interface QuerySpecification<T>
A reusable, composable condition for selecting entities, expressed with the JPA criteria API.

toPredicate(Root, CriteriaQuery, CriteriaBuilder) receives the query root, the query being built and the criteria builder, and returns the Predicate to use in the WHERE clause, or null for no restriction. Having access to the CriteriaQuery allows a specification to also influence the query, for example to make it distinct; use PredicateSpecification when only a predicate is needed. Specifications are passed to the methods of JpaSpecificationExecutor and can be combined with and(QuerySpecification), or(QuerySpecification) and not(QuerySpecification).

Similar to Spring Data JPA's Specification.

Since:
3.2
Author:
Denis Stepanov
  • Field Details

  • Method Details

    • not

      static <T> QuerySpecification<T> not(@Nullable QuerySpecification<T> spec)
      Negates the given QuerySpecification.
      Type Parameters:
      T - the type of the Root the resulting Specification operates on.
      Parameters:
      spec - The specification.
      Returns:
      negated specification}.
    • where

      static <T> QuerySpecification<T> where(@Nullable QuerySpecification<T> spec)
      Simple static factory method to add some syntactic sugar around a QuerySpecification.
      Type Parameters:
      T - the type of the Root the resulting Specification operates on.
      Parameters:
      spec - The specification.
      Returns:
      guaranteed to be not null.
    • where

      static <T> QuerySpecification<T> where(@Nullable PredicateSpecification<T> spec)
      Simple static factory method to add some syntactic sugar around a PredicateSpecification.
      Type Parameters:
      T - the type of the Root the resulting Specification operates on.
      Parameters:
      spec - The specification.
      Returns:
      query specification.
    • and

      default QuerySpecification<T> and(@Nullable QuerySpecification<T> other)
      ANDs the given QuerySpecification to the current one.
      Parameters:
      other - The other predicate.
      Returns:
      The conjunction of the specifications
    • or

      default QuerySpecification<T> or(@Nullable QuerySpecification<T> other)
      ORs the given specification to the current one.
      Parameters:
      other - The other predicate.
      Returns:
      The disjunction of the specifications
    • and

      default QuerySpecification<T> and(@Nullable PredicateSpecification<T> other)
      ANDs the given PredicateSpecification to the current one.
      Parameters:
      other - The other predicate.
      Returns:
      The conjunction of the specifications
    • or

      default QuerySpecification<T> or(@Nullable PredicateSpecification<T> other)
      ORs the given PredicateSpecification to the current one.
      Parameters:
      other - The other predicate.
      Returns:
      The disjunction of the specifications
    • toPredicate

      @Nullable jakarta.persistence.criteria.Predicate toPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaQuery<?> query, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder)
      Creates a WHERE clause predicate for the given entity Root and a criteria query.
      Parameters:
      root - The entity root
      query - The criteria query
      criteriaBuilder - The criteria builder
      Returns:
      a Predicate