Class ApiJpaRepositoryUtils<T,​K extends Serializable>

  • All Implemented Interfaces:
    org.springframework.data.jpa.repository.JpaRepository<T,​K>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>, org.springframework.data.jpa.repository.support.JpaRepositoryImplementation<T,​K>, org.springframework.data.repository.CrudRepository<T,​K>, org.springframework.data.repository.PagingAndSortingRepository<T,​K>, org.springframework.data.repository.query.QueryByExampleExecutor<T>, org.springframework.data.repository.Repository<T,​K>
    Direct Known Subclasses:
    ApiJpaRepositoryImpl

    public class ApiJpaRepositoryUtils<T,​K extends Serializable>
    extends org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​K>
    • Constructor Summary

      Constructors 
      Constructor Description
      ApiJpaRepositoryUtils​(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,​?> entityInformation, javax.persistence.EntityManager entityManager)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(org.springframework.data.jpa.domain.Specification<T> specs, Class<P> projectionClass)  
      protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(org.springframework.data.jpa.domain.Specification<T> specs, Class<P> projectionClass, Collection<String> fields)
      Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
      protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(org.springframework.data.jpa.domain.Specification<T> specs, Class<P> projectionClass, Collection<String> fields, org.springframework.data.domain.Sort sort)
      Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
      protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(org.springframework.data.jpa.domain.Specification<T> specs, Class<P> projectionClass, org.springframework.data.domain.Pageable pageable)
      Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
      protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(org.springframework.data.jpa.domain.Specification<T> specs, Class<P> projectionClass, org.springframework.data.domain.Pageable pageable, Collection<String> fields)
      Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
      protected javax.persistence.TypedQuery<javax.persistence.Tuple> createTupleTypedQuery​(javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> tupleQuery, org.springframework.data.domain.Pageable pageable)
      Create a Tuple TypedQuery and sets the limit and offset based on the Pageable.
      protected <P> List<PropertyDescriptor> getProjectionProperties​(Class<P> projectionClass)
      Extract and returns the properties that will be consumed by the projection type.
      protected <P> List<P> mapFromTupleList​(List<javax.persistence.Tuple> tuples, Class<P> projectionClass)
      Map the TupleElement for object instances based on the given projection class.
      protected <P> List<javax.persistence.criteria.Selection<?>> mapProjectionSelectionRecursively​(javax.persistence.criteria.From<?,​?> from, Class<P> projectionClass, Collection<String> fields)
      Specify the selection items that are to be returned in the query result based on the given projection class.
      protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setOrder​(javax.persistence.criteria.CriteriaQuery<Q> query, javax.persistence.criteria.Root<T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, List<javax.persistence.criteria.Order> orders)
      Add the Sort specification, if exists, to the given CriteriaQuery.
      protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setOrder​(javax.persistence.criteria.CriteriaQuery<Q> query, javax.persistence.criteria.Root<T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, org.springframework.data.domain.Pageable pageable)
      Add the Sort specification, if exists, to the given CriteriaQuery.
      protected <Q> javax.persistence.TypedQuery<Q> setPage​(javax.persistence.TypedQuery<Q> query, org.springframework.data.domain.Pageable pageable)
      Set the limit and offset based on the Pageable, if exists, to the given TypedQuery.
      protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setSpecifications​(javax.persistence.criteria.CriteriaQuery<Q> query, javax.persistence.criteria.Root<T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, org.springframework.data.jpa.domain.Specification<T> specs)
      Convert the given Specification to Predicate, if exists, to the given CriteriaQuery.
      • Methods inherited from class org.springframework.data.jpa.repository.support.SimpleJpaRepository

        count, count, count, delete, deleteAll, deleteAll, deleteAllInBatch, deleteById, deleteInBatch, exists, existsById, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAllById, findById, findOne, findOne, flush, getCountQuery, getCountQuery, getDomainClass, getOne, getQuery, getQuery, getQuery, getQuery, getQueryHints, getRepositoryMethodMetadata, readPage, readPage, save, saveAll, saveAndFlush, setEscapeCharacter, setRepositoryMethodMetadata
    • Constructor Detail

      • ApiJpaRepositoryUtils

        public ApiJpaRepositoryUtils​(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,​?> entityInformation,
                                     javax.persistence.EntityManager entityManager)
    • Method Detail

      • setSpecifications

        protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setSpecifications​(javax.persistence.criteria.CriteriaQuery<Q> query,
                                                                                    javax.persistence.criteria.Root<T> root,
                                                                                    javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                                    org.springframework.data.jpa.domain.Specification<T> specs)
        Convert the given Specification to Predicate, if exists, to the given CriteriaQuery.
        Parameters:
        query - current CriteriaQuery.
        root - a root type in the from clause.
        criteriaBuilder - criteria queries constructor.
        specs - can be null.
        Returns:
        the given CriteriaQuery.
      • setOrder

        protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setOrder​(javax.persistence.criteria.CriteriaQuery<Q> query,
                                                                           javax.persistence.criteria.Root<T> root,
                                                                           javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                           org.springframework.data.domain.Pageable pageable)
        Add the Sort specification, if exists, to the given CriteriaQuery.
        Parameters:
        query - current CriteriaQuery.
        root - a root type in the from clause.
        criteriaBuilder - criteria queries constructor.
        pageable - can be null.
        Returns:
        the given CriteriaQuery.
      • setOrder

        protected <Q> javax.persistence.criteria.CriteriaQuery<Q> setOrder​(javax.persistence.criteria.CriteriaQuery<Q> query,
                                                                           javax.persistence.criteria.Root<T> root,
                                                                           javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
                                                                           List<javax.persistence.criteria.Order> orders)
        Add the Sort specification, if exists, to the given CriteriaQuery.
        Parameters:
        query - current CriteriaQuery.
        root - a root type in the from clause.
        criteriaBuilder - criteria queries constructor.
        orders - list of order that defines an ordering over the query results
        Returns:
        the given CriteriaQuery.
      • setPage

        protected <Q> javax.persistence.TypedQuery<Q> setPage​(javax.persistence.TypedQuery<Q> query,
                                                              org.springframework.data.domain.Pageable pageable)
        Set the limit and offset based on the Pageable, if exists, to the given TypedQuery.
        Parameters:
        query - current TypedQuery.
        pageable - can be null.
        Returns:
        the given TypedQuery.
      • createTupleQuery

        protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(@Nullable
                                                                                                         org.springframework.data.jpa.domain.Specification<T> specs,
                                                                                                         Class<P> projectionClass,
                                                                                                         @Nullable
                                                                                                         org.springframework.data.domain.Pageable pageable,
                                                                                                         @Nullable
                                                                                                         Collection<String> fields)
        Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
        Parameters:
        specs - can be null.
        projectionClass - the projection to be used, must not be null.
        pageable - can be null.
        fields - can be null.
        Returns:
        Tuple CriteriaQuery based on the given projection class
      • createTupleQuery

        protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(@Nullable
                                                                                                         org.springframework.data.jpa.domain.Specification<T> specs,
                                                                                                         Class<P> projectionClass,
                                                                                                         @Nullable
                                                                                                         org.springframework.data.domain.Pageable pageable)
        Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
        Parameters:
        specs - can be null.
        projectionClass - the projection to be used, must not be null.
        pageable - can be null.
        Returns:
        Tuple CriteriaQuery based on the given projection class
      • createTupleQuery

        protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(@Nullable
                                                                                                         org.springframework.data.jpa.domain.Specification<T> specs,
                                                                                                         Class<P> projectionClass)
      • createTupleQuery

        protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(@Nullable
                                                                                                         org.springframework.data.jpa.domain.Specification<T> specs,
                                                                                                         Class<P> projectionClass,
                                                                                                         @Nullable
                                                                                                         Collection<String> fields)
        Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
        Parameters:
        specs - can be null.
        projectionClass - the projection to be used, must not be null.
        fields - can be null.
        Returns:
        Tuple CriteriaQuery based on the given projection class
      • createTupleQuery

        protected <P> javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> createTupleQuery​(@Nullable
                                                                                                         org.springframework.data.jpa.domain.Specification<T> specs,
                                                                                                         Class<P> projectionClass,
                                                                                                         @Nullable
                                                                                                         Collection<String> fields,
                                                                                                         org.springframework.data.domain.Sort sort)
        Create a Tuple CriteriaQuery object that returns a tuple of objects as its result based on the given projection class with the given Specification and Sort criteria specified in the Pageable object.
        Parameters:
        specs - can be null.
        projectionClass - the projection to be used, must not be null.
        fields - can be null.
        sort - defines an ordering over the query results, can be null.
        Returns:
        Tuple CriteriaQuery based on the given projection class
      • createTupleTypedQuery

        protected javax.persistence.TypedQuery<javax.persistence.Tuple> createTupleTypedQuery​(javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> tupleQuery,
                                                                                              org.springframework.data.domain.Pageable pageable)
        Create a Tuple TypedQuery and sets the limit and offset based on the Pageable.
        Parameters:
        tupleQuery - a Tuple CriteriaQuery object.
        pageable - can be null.
        Returns:
        Tuple TypedQuery with pagination
      • mapProjectionSelectionRecursively

        protected <P> List<javax.persistence.criteria.Selection<?>> mapProjectionSelectionRecursively​(javax.persistence.criteria.From<?,​?> from,
                                                                                                      Class<P> projectionClass,
                                                                                                      Collection<String> fields)
        Specify the selection items that are to be returned in the query result based on the given projection class.
        Parameters:
        from - the From that the PropertyPath expression is based on
        projectionClass - the projection to be used, must not be null.
        fields - can be null.
        Returns:
        a List of Selection expressions to be used in Tuple CriteriaQuery.
        See Also:
        CriteriaQuery.multiselect(Selection...), QueryUtils.toSelectionRecursively(From, PropertyPath)
      • getProjectionProperties

        protected <P> List<PropertyDescriptor> getProjectionProperties​(Class<P> projectionClass)
        Extract and returns the properties that will be consumed by the projection type.
        Parameters:
        projectionClass - must not be null.
        Returns:
        list of properties that will be consumed
        See Also:
        ProjectionInformation.getInputProperties(), ProjectionFactory.getProjectionInformation(Class)
      • mapFromTupleList

        protected <P> List<P> mapFromTupleList​(List<javax.persistence.Tuple> tuples,
                                               Class<P> projectionClass)
        Map the TupleElement for object instances based on the given projection class.
        Parameters:
        tuples - list of TupleElement, must not be null.
        projectionClass - must not be null.
        Returns:
        list of projection object mapped from the TupleElement.
        See Also:
        ProjectionFactory.createProjection(Class, Object)