Class ApiJpaRepositoryUtils<T,K extends Serializable>
- java.lang.Object
-
- org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,K>
-
- com.totvs.tjf.api.jpa.repository.impl.ApiJpaRepositoryUtils<T,K>
-
- 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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
object.protected javax.persistence.TypedQuery<javax.persistence.Tuple>
createTupleTypedQuery(javax.persistence.criteria.CriteriaQuery<javax.persistence.Tuple> tupleQuery, org.springframework.data.domain.Pageable pageable)
Create aTuple
TypedQuery
and sets thelimit
andoffset
based on thePageable
.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 theTupleElement
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 theSort
specification, if exists, to the givenCriteriaQuery
.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 theSort
specification, if exists, to the givenCriteriaQuery
.protected <Q> javax.persistence.TypedQuery<Q>
setPage(javax.persistence.TypedQuery<Q> query, org.springframework.data.domain.Pageable pageable)
Set thelimit
andoffset
based on thePageable
, if exists, to the givenTypedQuery
.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 givenSpecification
toPredicate
, if exists, to the givenCriteriaQuery
.-
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 givenSpecification
toPredicate
, if exists, to the givenCriteriaQuery
.- Parameters:
query
- currentCriteriaQuery
.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 theSort
specification, if exists, to the givenCriteriaQuery
.- Parameters:
query
- currentCriteriaQuery
.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 theSort
specification, if exists, to the givenCriteriaQuery
.- Parameters:
query
- currentCriteriaQuery
.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 thelimit
andoffset
based on thePageable
, if exists, to the givenTypedQuery
.- Parameters:
query
- currentTypedQuery
.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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
CriteriaQuery
object that returns a tuple of objects as its result based on the given projection class with the givenSpecification
andSort
criteria specified in thePageable
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 aTuple
TypedQuery
and sets thelimit
andoffset
based on thePageable
.- Parameters:
tupleQuery
- aTuple
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
- theFrom
that thePropertyPath
expression is based onprojectionClass
- the projection to be used, must not be null.fields
- can be null.- Returns:
- a
List
ofSelection
expressions to be used inTuple
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 theTupleElement
for object instances based on the given projection class.- Parameters:
tuples
- list ofTupleElement
, must not be null.projectionClass
- must not be null.- Returns:
- list of projection object mapped from the
TupleElement
. - See Also:
ProjectionFactory.createProjection(Class, Object)
-
-