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

    Constructors
    Constructor
    Description
    JpaSpecificationExecutionStrategy(org.springframework.data.jpa.repository.JpaSpecificationExecutor<T> repository)
    Constructs a new execution strategy using the provided repository.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      findAll in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - the JPA specification to apply additional filters
      pageable - 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:
      findAll in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - 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:
      findAll in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - the JPA specification to apply additional filters
      pageable - the pagination information
      projection - 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:
      findAll in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - the JPA specification to apply additional filters
      projection - 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:
      findOne in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - 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:
      findOne in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - the JPA specification to apply additional filters
      projection - 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:
      exists in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - 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:
      count in interface QueryExecutionStrategy<T>
      Parameters:
      predicate - the QueryDSL predicate to filter results
      spec - the JPA specification to apply additional filters
      Returns:
      the count of entities matching the criteria