Interface JpaSpecificationExecutor<T>

Type Parameters:
T - The entity type
All Known Subinterfaces:
ArraysEntityRepository, AuthenticationRepository, AuthorRepository, BasicTypesRepository, CarRepository, ChapterRepository, ChildRepository, ClientCategoryRepository, ClientRepository, DeviceRepository, DocumentRepository, EmbeddedOwnerRepository, EmployeeFieldAccessRepository, EmployeeMixedAccessEmbeddedIdRepository, EmployeeMixedAccessRepository, EmployeePropertyAccessRepository, FoodRepository, PersonRepository, PersonRepository, PublisherRepository, PurchaseOrderRepository, StudentRepository, TrainRepository
All Known Implementing Classes:
BookRepository

public interface JpaSpecificationExecutor<T>
Adds methods to a repository that find, count, check, delete and update entities selected by a specification built at runtime with the JPA criteria API (CriteriaBuilder), rather than by a query derived from the method name at compile time. This is useful when the filter depends on runtime input, for example optional search fields.

A QuerySpecification or PredicateSpecification returns the Predicate for the WHERE clause, and specifications can be combined with and, or and not. A null specification or predicate selects all entities. Despite the name, the criteria API is implemented by Micronaut Data itself, so this interface can be used with the JDBC, R2DBC and MongoDB repositories as well as with JPA.

Similar to Spring Data JPA's JpaSpecificationExecutor.

Since:
3.2
Author:
Denis Stepanov
  • Method Details

    • findOne

      Optional<T> findOne(@Nullable @Nullable @Nullable QuerySpecification<T> spec)
      Returns a single entity matching the given QuerySpecification.
      Parameters:
      spec - The query specification
      Returns:
      optional found result
    • findOne

      Optional<T> findOne(@Nullable @Nullable @Nullable PredicateSpecification<T> spec)
      Returns a single entity matching the given PredicateSpecification.
      Parameters:
      spec - The query specification
      Returns:
      optional found result
    • findAll

      List<T> findAll(@Nullable @Nullable @Nullable QuerySpecification<T> spec)
      Returns all entities matching the given QuerySpecification.
      Parameters:
      spec - The query specification
      Returns:
      found results
    • findAll

      List<T> findAll(@Nullable @Nullable @Nullable PredicateSpecification<T> spec)
      Returns all entities matching the given PredicateSpecification.
      Parameters:
      spec - The query specification
      Returns:
      found results
    • findAll

      Page<T> findAll(@Nullable @Nullable @Nullable QuerySpecification<T> spec, Pageable pageable)
      Returns a Page of entities matching the given QuerySpecification.
      Parameters:
      spec - The query specification
      pageable - The pageable object
      Returns:
      a page
    • findAll

      Page<T> findAll(@Nullable @Nullable @Nullable PredicateSpecification<T> spec, Pageable pageable)
      Returns a Page of entities matching the given QuerySpecification.
      Parameters:
      spec - The query specification
      pageable - The pageable object
      Returns:
      a page
    • findAll

      List<T> findAll(@Nullable @Nullable @Nullable QuerySpecification<T> spec, Sort sort)
      Returns all entities matching the given QuerySpecification and Sort.
      Parameters:
      spec - The query specification
      sort - The sort object
      Returns:
      found results
    • findAll

      List<T> findAll(@Nullable @Nullable @Nullable PredicateSpecification<T> spec, Sort sort)
      Returns all entities matching the given QuerySpecification and Sort.
      Parameters:
      spec - The query specification
      sort - The sort object
      Returns:
      found results
    • findAll

      <R> List<R> findAll(@Nullable @Nullable @Nullable CriteriaQueryBuilder<R> builder)
      Find all using build criteria query.
      Type Parameters:
      R - the result type
      Parameters:
      builder - The criteria query builder
      Returns:
      the number records updated.
      Since:
      3.5.0
    • findOne

      <R> R findOne(@Nullable @Nullable @Nullable CriteriaQueryBuilder<R> builder)
      Find one using build criteria query.
      Type Parameters:
      R - the result type
      Parameters:
      builder - The criteria query builder
      Returns:
      the number records updated.
      Since:
      3.5.0
    • count

      long count(@Nullable @Nullable @Nullable QuerySpecification<T> spec)
      Returns the number of instances that the given QuerySpecification will return.
      Parameters:
      spec - The query specification
      Returns:
      the number of instances.
    • count

      long count(@Nullable @Nullable @Nullable PredicateSpecification<T> spec)
      Returns the number of instances that the given QuerySpecification will return.
      Parameters:
      spec - The query specification
      Returns:
      the number of instances.
    • exists

      boolean exists(@Nullable @Nullable @Nullable QuerySpecification<T> spec)
      Returns whether an instance was found for the given QuerySpecification.
      Parameters:
      spec - The query specification
      Returns:
      the number of instances.
      Since:
      3.8
    • exists

      boolean exists(@Nullable @Nullable @Nullable PredicateSpecification<T> spec)
      Returns whether an instance was found for the given PredicateSpecification.
      Parameters:
      spec - The query specification
      Returns:
      the number of instances.
      Since:
      3.8
    • deleteAll

      long deleteAll(@Nullable @Nullable @Nullable DeleteSpecification<T> spec)
      Deletes all entities matching the given DeleteSpecification.
      Parameters:
      spec - The delete specification
      Returns:
      the number records deleted.
    • deleteAll

      long deleteAll(@Nullable @Nullable @Nullable PredicateSpecification<T> spec)
      Deletes all entities matching the given PredicateSpecification.
      Parameters:
      spec - The delete specification
      Returns:
      the number records deleted.
    • deleteAll

      long deleteAll(@Nullable @Nullable @Nullable CriteriaDeleteBuilder<T> builder)
      Delete all entities using build criteria query.
      Parameters:
      builder - The delete criteria query builder
      Returns:
      the number records updated.
      Since:
      3.5.0
    • updateAll

      long updateAll(@Nullable @Nullable @Nullable UpdateSpecification<T> spec)
      Updates all entities matching the given UpdateSpecification.
      Parameters:
      spec - The update specification
      Returns:
      the number records updated.
    • updateAll

      long updateAll(@Nullable @Nullable @Nullable CriteriaUpdateBuilder<T> builder)
      Updates all entities using build criteria query.
      Parameters:
      builder - The update criteria query builder
      Returns:
      the number records updated.
      Since:
      3.5.0