Class JpaSpecificationFinder<M,E,F extends it.tidalwave.util.Finder<M>,R extends org.springframework.data.jpa.repository.JpaSpecificationExecutor<E>>

java.lang.Object
it.tidalwave.util.spi.HierarchicFinderSupport<M,F>
it.tidalwave.util.spring.jpa.JpaSpecificationFinder<M,E,F,R>
Type Parameters:
M - the static type of the model object
E - the static type of the JPA entity
F - the static type of the Finder
R - the static type of the repository
All Implemented Interfaces:
it.tidalwave.util.Finder<M>, Serializable, Cloneable

public class JpaSpecificationFinder<M,E,F extends it.tidalwave.util.Finder<M>,R extends org.springframework.data.jpa.repository.JpaSpecificationExecutor<E>> extends it.tidalwave.util.spi.HierarchicFinderSupport<M,F>
A Finder that works with a repository extending JpaSpecificationExecutor.
Author:
Fabrizio Giudici
See Also:
Stereotype:
Finder
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     

    Nested classes/interfaces inherited from interface it.tidalwave.util.Finder

    it.tidalwave.util.Finder.InMemorySortCriterion<U extends Object>, it.tidalwave.util.Finder.SortCriterion, it.tidalwave.util.Finder.SortDirection
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Function<E,M>
     
    protected final R
     
     

    Fields inherited from class it.tidalwave.util.spi.HierarchicFinderSupport

    firstResult, maxResults
  • Constructor Summary

    Constructors
    Constructor
    Description
    The required constructor for subclasses of HierarchicFinderSupport.
    JpaSpecificationFinder(R repository, Function<E,M> entityToModel)
    Creates a new instance given a repository and a model-to-entity transformer.
  • Method Summary

    Modifier and Type
    Method
    Description
    static it.tidalwave.util.Finder.SortCriterion
    by(Enum<?> sortingKey)
    Creates a Finder.SortCriterion by key.
    protected void
    composeSpecification(jakarta.persistence.criteria.Root<E> root, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, List<? super jakarta.persistence.criteria.Predicate> predicates)
     
    protected final List<M>
    protected org.springframework.data.jpa.domain.Specification<E>
     
    sort(it.tidalwave.util.Finder.SortCriterion criterion, it.tidalwave.util.Finder.SortDirection direction)

    Methods inherited from class it.tidalwave.util.spi.HierarchicFinderSupport

    clone, clone, clonedWith, computeResults, count, from, getContexts, getSource, max, ofType, results, sort, toString, withContext

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface it.tidalwave.util.Finder

    firstResult, forEach, from, from, iterator, max, max, optionalFirstResult, optionalResult, result, stream
  • Field Details

    • repository

      @Nonnull protected final R extends org.springframework.data.jpa.repository.JpaSpecificationExecutor<E> repository
    • entityToModel

      @Nonnull protected final Function<E,M> entityToModel
    • sorters

      @Nonnull protected final List<JpaSpecificationFinder.JpaSorter> sorters
  • Constructor Details

    • JpaSpecificationFinder

      public JpaSpecificationFinder(@Nonnull R repository, @Nonnull Function<E,M> entityToModel)
      Creates a new instance given a repository and a model-to-entity transformer.
      Parameters:
      repository - the repository
      entityToModel - the transformer
    • JpaSpecificationFinder

      public JpaSpecificationFinder(@Nonnull JpaSpecificationFinder<M,E,F,R> other, @Nonnull Object override)
      The required constructor for subclasses of HierarchicFinderSupport.
  • Method Details

    • sort

      @Nonnull public F sort(@Nonnull it.tidalwave.util.Finder.SortCriterion criterion, @Nonnull it.tidalwave.util.Finder.SortDirection direction)
      Specified by:
      sort in interface it.tidalwave.util.Finder<M>
      Overrides:
      sort in class it.tidalwave.util.spi.HierarchicFinderSupport<M,F extends it.tidalwave.util.Finder<M>>
    • by

      @Nonnull public static it.tidalwave.util.Finder.SortCriterion by(@Nonnull Enum<?> sortingKey)
      Creates a Finder.SortCriterion by key.
      Parameters:
      sortingKey - the key
      Returns:
      the SortCriterion
    • computeNeededResults

      @Nonnull protected final List<M> computeNeededResults()
      Overrides:
      computeNeededResults in class it.tidalwave.util.spi.HierarchicFinderSupport<M,F extends it.tidalwave.util.Finder<M>>
    • getSpecification

      @Nonnull protected org.springframework.data.jpa.domain.Specification<E> getSpecification()
    • composeSpecification

      protected void composeSpecification(@Nonnull jakarta.persistence.criteria.Root<E> root, @Nonnull jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, @Nonnull List<? super jakarta.persistence.criteria.Predicate> predicates)