Interface JpaSpecificationExecutor<T>
- All Known Subinterfaces:
JpaRepositoryImplementation<T,ID>
- All Known Implementing Classes:
QuerydslJpaRepository,SimpleJpaRepository
public interface JpaSpecificationExecutor<T>
Interface to allow execution of
Specifications based on the JPA criteria API.- Author:
- Oliver Gierke, Christoph Strobl, Diego Krupitza
-
Method Summary
Modifier and TypeMethodDescriptionlongcount(Specification<T> spec) Returns the number of instances that the givenSpecificationwill return.longdelete(Specification<T> spec) Deletes by theSpecificationand returns the number of rows deleted.booleanexists(Specification<T> spec) Checks whether the data store contains elements that match the givenSpecification.findAll(Specification<T> spec) Returns all entities matching the givenSpecification.findAll(Specification<T> spec, Pageable pageable) Returns aPageof entities matching the givenSpecification.findAll(Specification<T> spec, Sort sort) Returns all entities matching the givenSpecificationandSort.<S extends T,R>
RfindBy(Specification<T> spec, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction) Returns entities matching the givenSpecificationapplying thequeryFunctionthat defines the query and its result type.findOne(Specification<T> spec) Returns a single entity matching the givenSpecificationorOptional.empty()if none found.
-
Method Details
-
findOne
Returns a single entity matching the givenSpecificationorOptional.empty()if none found.- Parameters:
spec- can be null.- Returns:
- never null.
- Throws:
IncorrectResultSizeDataAccessException- if more than one entity found.
-
findAll
Returns all entities matching the givenSpecification.- Parameters:
spec- can be null.- Returns:
- never null.
-
findAll
Returns aPageof entities matching the givenSpecification.- Parameters:
spec- can be null.pageable- must not be null.- Returns:
- never null.
-
findAll
Returns all entities matching the givenSpecificationandSort.- Parameters:
spec- can be null.sort- must not be null.- Returns:
- never null.
-
count
Returns the number of instances that the givenSpecificationwill return.- Parameters:
spec- theSpecificationto count instances for. Can be null.- Returns:
- the number of instances.
-
exists
Checks whether the data store contains elements that match the givenSpecification.- Parameters:
spec- theSpecificationto use for the existence check. Must not be null.- Returns:
trueif the data store contains elements that match the givenSpecificationotherwisefalse.
-
delete
Deletes by theSpecificationand returns the number of rows deleted.- Parameters:
spec- theSpecificationto use for the existence check. Must not be null.- Returns:
- the number of entities deleted
-
findBy
<S extends T,R> R findBy(Specification<T> spec, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction) Returns entities matching the givenSpecificationapplying thequeryFunctionthat defines the query and its result type.- Parameters:
spec- – must not be null.queryFunction- – the query function defining projection, sorting, and the result type- Returns:
- all entities matching the given Example.
- Since:
- 3.0
-