Class WebQueryRepositoryImpl<E>

java.lang.Object
in.co.akshitbansal.springwebquery.repository.WebQueryRepositoryImpl<E>
Type Parameters:
E - entity type handled by the repository
All Implemented Interfaces:
WebQueryRepository<E>, org.springframework.data.repository.core.support.RepositoryMetadataAccess

public class WebQueryRepositoryImpl<E> extends Object implements WebQueryRepository<E>, org.springframework.data.repository.core.support.RepositoryMetadataAccess
JPA-based WebQueryRepository repository fragment implementation backed by Criteria queries and rsql-jpa.

This implementation handles filtering, sorting, pagination, and projection for a repository method invocation. It builds tuple-based select queries through the supplied SelectionsProvider, validates and maps filter and sort paths against the supplied DTO type, delegates predicate creation to rsql-jpa, and converts the resulting tuples into the requested DTO type.

When page metadata is needed, the same filter rules are reused for a separate count query. The interface Javadoc remains the main public API description; the helper methods in this class explain how the JPA-backed implementation realizes that behavior.

The repository-wide defaults used by the overloads that do not accept explicit validation settings are sourced from the properties spring-web-query.filtering.allow-and-operation, spring-web-query.filtering.allow-or-operation, and spring-web-query.filtering.max-ast-depth.

  • Constructor Summary

    Constructors
    Constructor
    Description
    WebQueryRepositoryImpl(@NonNull jakarta.persistence.EntityManager entityManager, @NonNull cz.jirutka.rsql.parser.RSQLParser rsqlParser, @NonNull ValidationRSQLVisitorFactory validationRSQLVisitorFactory, @NonNull List<io.github.perplexhub.rsql.RSQLCustomPredicate<?>> customPredicates, @NonNull DTOToEntityPathMapperFactory pathMapperFactory, @NonNull SortableFieldValidator sortableFieldValidator, @NonNull TupleConverterFactory tupleConverterFactory, boolean globalAllowAndOperation, boolean globalAllowOrOperation, int globalMaxASTDepth)
    Creates the repository implementation with all collaborating components and global validation defaults.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    count(@Nullable String rsqlQuery, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<?> dtoClass)
    Counts rows matching the supplied filter using repository defaults.
    long
    count(@Nullable String rsqlQuery, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<?> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
    Counts rows matching the supplied filter using explicit validation settings.
    <D> List<D>
    findAll(@Nullable String rsqlQuery, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<D> dtoClass)
    Executes a projected result query using repository defaults.
    <D> List<D>
    findAll(@Nullable String rsqlQuery, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<D> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
    Executes a projected result query using explicit validation settings.
    <D> org.springframework.data.domain.Page<D>
    findAllPaged(@Nullable String rsqlQuery, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<D> dtoClass)
    Executes a paged projected query using repository defaults.
    <D> org.springframework.data.domain.Page<D>
    findAllPaged(@Nullable String rsqlQuery, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull Class<D> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
    Executes a paged projected query using explicit validation settings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface in.co.akshitbansal.springwebquery.repository.WebQueryRepository

    count, findAll, findAllPaged
  • Constructor Details

    • WebQueryRepositoryImpl

      public WebQueryRepositoryImpl(@NonNull @NonNull jakarta.persistence.EntityManager entityManager, @NonNull @NonNull cz.jirutka.rsql.parser.RSQLParser rsqlParser, @NonNull @NonNull ValidationRSQLVisitorFactory validationRSQLVisitorFactory, @NonNull @NonNull List<io.github.perplexhub.rsql.RSQLCustomPredicate<?>> customPredicates, @NonNull @NonNull DTOToEntityPathMapperFactory pathMapperFactory, @NonNull @NonNull SortableFieldValidator sortableFieldValidator, @NonNull @NonNull TupleConverterFactory tupleConverterFactory, @Value("${spring-web-query.filtering.allow-and-operation:true}") boolean globalAllowAndOperation, @Value("${spring-web-query.filtering.allow-or-operation:false}") boolean globalAllowOrOperation, @Value("${spring-web-query.filtering.max-ast-depth:1}") int globalMaxASTDepth)
      Creates the repository implementation with all collaborating components and global validation defaults.
  • Method Details

    • findAll

      public <D> List<D> findAll(@Nullable String rsqlQuery, @NonNull @NonNull org.springframework.data.domain.Pageable pageable, @NonNull @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<D> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
      Executes a projected result query using explicit validation settings.
      Specified by:
      findAll in interface WebQueryRepository<E>
      Type Parameters:
      D - projected DTO type
      Parameters:
      rsqlQuery - optional RSQL filter expression
      pageable - requested paging and sorting information
      selectionsProvider - callback that defines the tuple projection
      specificationCustomizer - optional hook to amend the generated filter specification before it is applied
      dtoClass - DTO type whose fields are used for filtering and sorting and whose shape is used for result projection
      allowAndOperation - whether logical AND is allowed in the RSQL expression
      allowOrOperation - whether logical OR is allowed in the RSQL expression
      maxASTDepth - maximum RSQL AST depth accepted during validation
      Returns:
      projected results for the requested page window, ordered according to the translated sort instructions
    • findAll

      public <D> List<D> findAll(@Nullable String rsqlQuery, @NonNull @NonNull org.springframework.data.domain.Pageable pageable, @NonNull @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<D> dtoClass)
      Executes a projected result query using repository defaults.
      Specified by:
      findAll in interface WebQueryRepository<E>
      Type Parameters:
      D - projected DTO type
      Parameters:
      rsqlQuery - optional RSQL filter expression
      pageable - requested paging and sorting information
      selectionsProvider - callback that defines the tuple projection
      specificationCustomizer - optional hook to amend the generated filter
      dtoClass - DTO type whose fields are used for filtering and sorting and whose shape is used for result projection
      Returns:
      projected results for the requested page window, ordered according to the translated sort instructions
    • count

      public long count(@Nullable String rsqlQuery, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<?> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
      Counts rows matching the supplied filter using explicit validation settings.
      Specified by:
      count in interface WebQueryRepository<E>
      Parameters:
      rsqlQuery - optional RSQL filter expression
      specificationCustomizer - optional hook to amend the generated filter
      dtoClass - DTO type whose fields are used for filter validation and path translation
      allowAndOperation - whether logical AND is allowed in the RSQL expression
      allowOrOperation - whether logical OR is allowed in the RSQL expression
      maxASTDepth - maximum RSQL AST depth accepted during validation
      Returns:
      number of matching rows after the generated and customized filter specification has been applied
    • count

      public long count(@Nullable String rsqlQuery, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<?> dtoClass)
      Counts rows matching the supplied filter using repository defaults.
      Specified by:
      count in interface WebQueryRepository<E>
      Parameters:
      rsqlQuery - optional RSQL filter expression
      specificationCustomizer - optional hook to amend the generated filter
      dtoClass - DTO type whose fields are used for filter validation and path translation
      Returns:
      number of matching rows after the generated and customized filter specification has been applied
    • findAllPaged

      public <D> org.springframework.data.domain.Page<D> findAllPaged(@Nullable String rsqlQuery, @NonNull @NonNull org.springframework.data.domain.Pageable pageable, @NonNull @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<D> dtoClass, boolean allowAndOperation, boolean allowOrOperation, int maxASTDepth)
      Executes a paged projected query using explicit validation settings.
      Specified by:
      findAllPaged in interface WebQueryRepository<E>
      Type Parameters:
      D - projected DTO type
      Parameters:
      rsqlQuery - optional RSQL filter expression
      pageable - requested paging and sorting information
      selectionsProvider - callback that defines the tuple projection
      specificationCustomizer - optional hook to amend the generated filter
      dtoClass - DTO type whose fields are used for filtering and sorting and whose shape is used for result projection
      allowAndOperation - whether logical AND is allowed in the RSQL expression
      allowOrOperation - whether logical OR is allowed in the RSQL expression
      maxASTDepth - maximum RSQL AST depth accepted during validation
      Returns:
      page of projected results together with paging metadata derived from the matching-row count
    • findAllPaged

      public <D> org.springframework.data.domain.Page<D> findAllPaged(@Nullable String rsqlQuery, @NonNull @NonNull org.springframework.data.domain.Pageable pageable, @NonNull @NonNull SelectionsProvider<E> selectionsProvider, @Nullable SpecificationCustomizer<E> specificationCustomizer, @NonNull @NonNull Class<D> dtoClass)
      Executes a paged projected query using repository defaults.
      Specified by:
      findAllPaged in interface WebQueryRepository<E>
      Type Parameters:
      D - projected DTO type
      Parameters:
      rsqlQuery - optional RSQL filter expression
      pageable - requested paging and sorting information
      selectionsProvider - callback that defines the tuple projection
      specificationCustomizer - optional hook to amend the generated filter
      dtoClass - DTO type whose fields are used for filtering and sorting and whose shape is used for result projection
      Returns:
      page of projected results together with paging metadata derived from the matching-row count