Class JpaSpecificationExecutionStrategy<T>
java.lang.Object
nl.datasteel.crudcraft.runtime.service.strategy.JpaSpecificationExecutionStrategy<T>
- All Implemented Interfaces:
QueryExecutionStrategy<T>
public class JpaSpecificationExecutionStrategy<T>
extends Object
implements QueryExecutionStrategy<T>
Executes queries using a
JpaSpecificationExecutor.-
Constructor Summary
ConstructorsConstructorDescriptionJpaSpecificationExecutionStrategy(org.springframework.data.jpa.repository.JpaSpecificationExecutor<T> repository) Constructs a new execution strategy using the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionlongcount(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Counts the number of entities matching the given predicate and specification.booleanexists(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Checks if any entities match the given predicate and specification.findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Executes a query with the given predicate and specification, returning all matching entities.<R> List<R> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, Class<R> projection) Finds all entities matching the given predicate and specification, projecting them to the specified type.org.springframework.data.domain.Page<T> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable) Executes a paginated query with the given predicate and specification.<R> org.springframework.data.domain.Page<R> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable, Class<R> projection) Finds all entities matching the given predicate and specification, paginated and projected to the specified type.findOne(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Finds a single entity matching the given predicate and specification.<R> Optional<R> findOne(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, Class<R> projection) Finds a single entity matching the given predicate and specification, projecting it to the specified type.
-
Constructor Details
-
JpaSpecificationExecutionStrategy
public JpaSpecificationExecutionStrategy(org.springframework.data.jpa.repository.JpaSpecificationExecutor<T> repository) Constructs a new execution strategy using the provided repository.- Parameters:
repository- the JPA specification executor to use for query execution
-
-
Method Details
-
findAll
public org.springframework.data.domain.Page<T> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable) Executes a paginated query with the given predicate and specification.- Specified by:
findAllin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filterspageable- the pagination information- Returns:
- a page of entities matching the criteria
-
findAll
public List<T> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Executes a query with the given predicate and specification, returning all matching entities.- Specified by:
findAllin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filters- Returns:
- a list of entities matching the criteria
-
findAll
public <R> org.springframework.data.domain.Page<R> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable, Class<R> projection) Finds all entities matching the given predicate and specification, paginated and projected to the specified type.- Specified by:
findAllin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filterspageable- the pagination informationprojection- the class of the projection type- Returns:
- a page of projected entities
-
findAll
public <R> List<R> findAll(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, Class<R> projection) Finds all entities matching the given predicate and specification, projecting them to the specified type.- Specified by:
findAllin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filtersprojection- the class of the projection type- Returns:
- a list of projected entities
-
findOne
public Optional<T> findOne(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Finds a single entity matching the given predicate and specification.- Specified by:
findOnein interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filters- Returns:
- an Optional containing the entity if found, or empty if not
-
findOne
public <R> Optional<R> findOne(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec, Class<R> projection) Finds a single entity matching the given predicate and specification, projecting it to the specified type.- Specified by:
findOnein interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filtersprojection- the class of the projection type- Returns:
- an Optional containing the projected entity, or empty if no match is found
-
exists
public boolean exists(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Checks if any entities match the given predicate and specification.- Specified by:
existsin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filters- Returns:
- true if at least one entity matches the criteria, false otherwise
-
count
public long count(com.querydsl.core.types.Predicate predicate, org.springframework.data.jpa.domain.Specification<T> spec) Counts the number of entities matching the given predicate and specification.- Specified by:
countin interfaceQueryExecutionStrategy<T>- Parameters:
predicate- the QueryDSL predicate to filter resultsspec- the JPA specification to apply additional filters- Returns:
- the count of entities matching the criteria
-