Class SelectionSpecificationImpl<T>
java.lang.Object
org.hibernate.query.specification.internal.SelectionSpecificationImpl<T>
- All Implemented Interfaces:
TypedQueryReference<T>
,QuerySpecification<T>
,SelectionSpecification<T>
public class SelectionSpecificationImpl<T>
extends Object
implements SelectionSpecification<T>, TypedQueryReference<T>
Standard implementation of SelectionSpecification
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.hibernate.query.specification.SelectionSpecification
SelectionSpecification.Augmentation<T>
-
Constructor Summary
ConstructorsConstructorDescriptionSelectionSpecificationImpl
(CriteriaQuery<T> criteriaQuery) SelectionSpecificationImpl
(Class<T> resultType) SelectionSpecificationImpl
(String hql, Class<T> resultType) -
Method Summary
Modifier and TypeMethodDescriptionaugment
(SelectionSpecification.Augmentation<T> augmentation) Add an augmentation to the specification.buildCriteria
(CriteriaBuilder builder) Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.createQuery
(EntityManager entityManager) Finalize the building and create executable query instance.createQuery
(Session session) Finalize the building and create executable query instance.createQuery
(SharedSessionContract session) createQuery
(StatelessSession session) Finalize the building and create executable query instance.Add a fetch path to the specification.getHints()
getName()
Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.final SelectionSpecification<T>
Sets the sorting for this selection specification.final SelectionSpecification<T>
Sets the ordering for this selection specification.restrict
(Restriction<? super T> restriction) Adds a restriction to the query specification.Adds an ordering to the selection specification.validate
(CriteriaBuilder builder) Validate the query.
-
Constructor Details
-
SelectionSpecificationImpl
-
SelectionSpecificationImpl
-
SelectionSpecificationImpl
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceTypedQueryReference<T>
-
getResultType
- Specified by:
getResultType
in interfaceTypedQueryReference<T>
-
getHints
- Specified by:
getHints
in interfaceTypedQueryReference<T>
-
reference
Description copied from interface:QuerySpecification
Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.- Specified by:
reference
in interfaceQuerySpecification<T>
- Specified by:
reference
in interfaceSelectionSpecification<T>
-
restrict
Description copied from interface:QuerySpecification
Adds a restriction to the query specification.- Specified by:
restrict
in interfaceQuerySpecification<T>
- Specified by:
restrict
in interfaceSelectionSpecification<T>
- Parameters:
restriction
- The restriction predicate to be added.- Returns:
this
for method chaining.
-
augment
Description copied from interface:SelectionSpecification
Add an augmentation to the specification.For example:
SelectionSpecification.create(Book.class) .augment((builder, query, book) -> // augment the query via JPA Criteria API query.where(builder.like(book.get(Book_.title), titlePattern)), builder.greaterThan(book.get(Book_.pages), minPages)) .orderBy(builder.asc(book.get(Book_.isbn))) .createQuery(session) .getResultList();
For complicated cases, aCriteriaDefinition
may be used within an augmentation to eliminate repetitive explicit references to theCriteriaBuilder
.SelectionSpecification.create(Book.class) .augment((builder, query, book) -> // eliminate explicit references to 'builder' new CriteriaDefinition<>(query) {{ where(like(entity.get(BasicEntity_.title), titlePattern), greaterThan(book.get(Book_.pages), minPages)); orderBy(asc(book.get(Book_.isbn))); }} ) .createQuery(session) .getResultList();
- Specified by:
augment
in interfaceSelectionSpecification<T>
- Parameters:
augmentation
- A function capable of modifying or augmenting a criteria query.- Returns:
this
for method chaining.
-
fetch
Description copied from interface:SelectionSpecification
Add a fetch path to the specification.- Specified by:
fetch
in interfaceSelectionSpecification<T>
- Parameters:
fetchPath
- The path to fetch- Returns:
this
for method chaining.
-
sort
Description copied from interface:SelectionSpecification
Adds an ordering to the selection specification. Appended to any previous ordering.- Specified by:
sort
in interfaceSelectionSpecification<T>
- Parameters:
order
- The ordering fragment to be added.- Returns:
this
for method chaining.
-
resort
Description copied from interface:SelectionSpecification
Sets the ordering for this selection specification. If ordering was already defined, this method drops the previous ordering in favor of the passedorders
.- Specified by:
resort
in interfaceSelectionSpecification<T>
- Parameters:
order
- The ordering fragment to be used.- Returns:
this
for method chaining.
-
resort
Description copied from interface:SelectionSpecification
Sets the sorting for this selection specification. If sorting was already defined, this method drops the previous sorting in favor of the passedorders
.- Specified by:
resort
in interfaceSelectionSpecification<T>
- Parameters:
orders
- The sorting fragments to be used.- Returns:
this
for method chaining.
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
- Specified by:
createQuery
in interfaceSelectionSpecification<T>
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
- Specified by:
createQuery
in interfaceSelectionSpecification<T>
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
- Specified by:
createQuery
in interfaceSelectionSpecification<T>
-
buildCriteria
Description copied from interface:SelectionSpecification
Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.If the returned criteria query is mutated, the mutations will not be not reflected in this specification.
- Specified by:
buildCriteria
in interfaceQuerySpecification<T>
- Specified by:
buildCriteria
in interfaceSelectionSpecification<T>
- Returns:
- a new criteria query
-
validate
Description copied from interface:QuerySpecification
Validate the query.- Specified by:
validate
in interfaceQuerySpecification<T>
- Specified by:
validate
in interfaceSelectionSpecification<T>
- Returns:
this
if everything is fine
-