Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions documentation/src/main/asciidoc/introduction/Interacting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1061,16 +1061,16 @@ var selection =

// add programmatic restrictions:
if (titlePattern != null)
selection.addRestriction(Restriction.like(Book_.title, namePattern));
selection.restrict(Restriction.like(Book_.title, namePattern));
if (isbns != null && !isbns.isEmpty())
selection.addRestriction(Restriction.in(Book_.isbn, isbns));
selection.restrict(Restriction.in(Book_.isbn, isbns));

// add programmatic ordering:
if (orderByTitle) selection.addOrdering(Order.asc(Book_.title));
if (orderByIsbn) selection.addOrdering(Order.asc(Book_.isbn));
if (orderByTitle) selection.sort(Order.asc(Book_.title));
if (orderByIsbn) selection.sort(Order.asc(Book_.isbn));

// add programmatic association fetching:
if (fetchPublisher) selection.addFetching(Path.from(Book.class).to(Book_.publisher));
if (fetchPublisher) selection.fetch(Path.from(Book.class).to(Book_.publisher));

// execute the query in the given session:
List<Book> matchingBooks = selection.createQuery(session).getResultList();
Expand All @@ -1088,10 +1088,10 @@ We need the following methods of link:{doc-javadoc-url}org/hibernate/query/progr
|===
| Method name | Purpose

| `addRestriction()` | Add a restriction on the query results
| `setOrder()`, `addOrder()` | Specify how the query results should be ordered
| `addFetching()` | Add a fetched association
| `addAugmentation()` | Add a custom function which directly manipulates the query
| `restrict()` | Add a `Restriction` on the query results
| `sort()`, `resort()` | Specify how the query results should be ordered
| `fetch()` | Add a fetched association `Path`
| `augment()` | Add a custom function which directly manipulates the query
|===

Alternatively, `Restriction` and `Order` can be used with <<paging-and-ordering,generated query or finder methods>>, and even with link:{doc-data-repositories-url}[Jakarta Data repositories].
Expand All @@ -1102,9 +1102,9 @@ The interface link:{doc-javadoc-url}org/hibernate/query/restriction/Path.html[`P
----
List<Book> booksForPublisher =
SelectionSpecification.create(Book.class)
.addRestriction(Path.from(Book.class).to(Book_.publisher).to(Publisher_.name)
.restrict(Path.from(Book.class).to(Book_.publisher).to(Publisher_.name)
.equalTo(publisherName))
.addFetching(Path.from(Book.class).to(Book_.publisher))
.fetch(Path.from(Book.class).to(Book_.publisher))
.createQuery(session)
.getResultList();
----
Expand All @@ -1115,7 +1115,7 @@ When `Restriction`, `Path`, and `Order` aren't expressive enough, we can _augmen
----
var books =
SelectionSpecification.create(Book.class)
.addAugmentation((builder, query, book) ->
.augment((builder, query, book) ->
// augment the query via JPA Criteria API
query.where(builder.like(book.get(Book_.title), titlePattern)))
.orderBy(builder.asc(book.get(Book_.isbn)))
Expand All @@ -1129,7 +1129,7 @@ For really advanced cases, `addAugmentation()` works quite nicely with <<criteri
----
var books =
SelectionSpecification.create(Book.class)
.addAugmentation((builder, query, book) ->
.augment((builder, query, book) ->
// eliminate explicit references to 'builder'
new CriteriaDefinition<>(query) {{
where(like(entity.get(BasicEntity_.title), titlePattern),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* Specialization of {@link QuerySpecification} for programmatic customization of
* {@linkplain MutationQuery mutation queries}.
* <p>
* The method {@link #addRestriction(Restriction)} allows application of additional
* The method {@link #restrict(Restriction)} allows application of additional
* {@linkplain Restriction filtering} to the mutated entity. The static factory
* methods of {@link Restriction} are used to express filtering criteria of various
* kinds.
* <p>
* Once all {@linkplain #addRestriction restrictions} are specified, call
* Once all {@linkplain #restrict restrictions} are specified, call
* {@link #createQuery createQuery()} to obtain an {@linkplain SelectionQuery
* executable mutation query object}.
*
Expand All @@ -43,7 +43,7 @@ public interface MutationSpecification<T> extends QuerySpecification<T> {
* Covariant override.
*/
@Override
MutationSpecification<T> addRestriction(Restriction<T> restriction);
MutationSpecification<T> restrict(Restriction<T> restriction);

/**
* A function capable of modifying or augmenting a criteria query.
Expand All @@ -62,7 +62,7 @@ interface Augmentation<T> {
*
* @return {@code this} for method chaining.
*/
MutationSpecification<T> addAugmentation(Augmentation<T> augmentation);
MutationSpecification<T> augment(Augmentation<T> augmentation);

/**
* Finalize the building and create the {@linkplain SelectionQuery} instance.
Expand All @@ -73,7 +73,7 @@ interface Augmentation<T> {
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain MutationQuery} based on a base HQL statement,
* allowing the addition of {@linkplain MutationSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain MutationSpecification#restrict restrictions}.
*
* @param hql The base HQL query (expected to be an {@code update} or {@code delete} query).
* @param mutationTarget The entity which is the target of the mutation.
Expand All @@ -91,7 +91,7 @@ static <T> MutationSpecification<T> create(Class<T> mutationTarget, String hql)
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain MutationQuery} based on the given criteria update,
* allowing the addition of {@linkplain MutationSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain MutationSpecification#restrict restrictions}.
*
* @param criteriaUpdate The criteria update query
*
Expand All @@ -104,7 +104,7 @@ static <T> MutationSpecification<T> create(CriteriaUpdate<T> criteriaUpdate) {
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain MutationQuery} based on the given criteria delete,
* allowing the addition of {@linkplain MutationSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain MutationSpecification#restrict restrictions}.
*
* @param criteriaDelete The criteria delete query
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface QuerySpecification<T> {
*
* @return {@code this} for method chaining.
*/
QuerySpecification<T> addRestriction(Restriction<T> restriction);
QuerySpecification<T> restrict(Restriction<T> restriction);

/**
* Finalize the building and create executable query instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
* Specialization of {@link QuerySpecification} for programmatic customization of
* {@linkplain SelectionQuery selection queries} with ordering and restriction criteria.
* <ul>
* <li>The method {@link #addRestriction(Restriction)} allows application of additional
* <li>The method {@link #restrict(Restriction)} allows application of additional
* {@linkplain Restriction filtering} to the query results. The static factory methods
* of {@link Restriction} are used to express filtering criteria of various kinds.
* <li>Refinement or replacement of the query sorting criteria is possible via the methods
* {@link #addOrdering(Order)} and {@link #setOrdering(List)}, together with the static
* {@link #sort(Order)} and {@link #resort(List)}, together with the static
* factory methods of {@link Order}.
* </ul>
* <p>
* Once all {@linkplain #addOrdering sorting} and {@linkplain #addRestriction restrictions}
* Once all {@linkplain #sort sorting} and {@linkplain #restrict restrictions}
* are specified, call {@link #createQuery createQuery()} to obtain an
* {@linkplain SelectionQuery executable selection query object}.
* <pre>
* SelectionSpecification.create(Book.class, "from Book where discontinued = false")
* .addRestriction(Restriction.contains(Book_.title, "hibernate", false))
* .setOrdering(Order.desc(Book_.title))
* .restrict(Restriction.contains(Book_.title, "hibernate", false))
* .sort(Order.desc(Book_.title))
* .fetch(Path.from(Book.class).to(Book_publisher))
* .createQuery(session) // obtain a SelectionQuery
* .setPage(Page.first(50))
* .getResultList();
Expand All @@ -62,7 +63,7 @@ public interface SelectionSpecification<T> extends QuerySpecification<T> {
*
* @return {@code this} for method chaining.
*/
SelectionSpecification<T> addOrdering(Order<T> order);
SelectionSpecification<T> sort(Order<T> order);

/**
* Sets the ordering for this selection specification.
Expand All @@ -73,7 +74,7 @@ public interface SelectionSpecification<T> extends QuerySpecification<T> {
*
* @return {@code this} for method chaining.
*/
SelectionSpecification<T> setOrdering(Order<T> order);
SelectionSpecification<T> resort(Order<T> order);

/**
* Sets the sorting for this selection specification.
Expand All @@ -84,13 +85,13 @@ public interface SelectionSpecification<T> extends QuerySpecification<T> {
*
* @return {@code this} for method chaining.
*/
SelectionSpecification<T> setOrdering(List<Order<T>> orders);
SelectionSpecification<T> resort(List<Order<T>> orders);

/**
* Covariant override.
*/
@Override
SelectionSpecification<T> addRestriction(Restriction<T> restriction);
SelectionSpecification<T> restrict(Restriction<T> restriction);

/**
* Add a fetch {@linkplain Path path} to the specification.
Expand All @@ -99,7 +100,7 @@ public interface SelectionSpecification<T> extends QuerySpecification<T> {
*
* @return {@code this} for method chaining.
*/
SelectionSpecification<T> addFetching(Path<T,?> fetchPath);
SelectionSpecification<T> fetch(Path<T,?> fetchPath);

/**
* A function capable of modifying or augmenting a criteria query.
Expand All @@ -117,7 +118,7 @@ interface Augmentation<T> {
* For example:
* <pre>
* SelectionSpecification.create(Book.class)
* .addAugmentation((builder, query, book) ->
* .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))
Expand All @@ -130,7 +131,7 @@ interface Augmentation<T> {
* the {@link CriteriaBuilder}.
* <pre>
* SelectionSpecification.create(Book.class)
* .addAugmentation((builder, query, book) ->
* .augment((builder, query, book) ->
* // eliminate explicit references to 'builder'
* new CriteriaDefinition<>(query) {{
* where(like(entity.get(BasicEntity_.title), titlePattern),
Expand All @@ -146,7 +147,7 @@ interface Augmentation<T> {
*
* @return {@code this} for method chaining.
*/
SelectionSpecification<T> addAugmentation(Augmentation<T> augmentation);
SelectionSpecification<T> augment(Augmentation<T> augmentation);

/**
* Covariant override.
Expand All @@ -157,8 +158,8 @@ interface Augmentation<T> {
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain SelectionQuery} for the given entity type,
* allowing the addition of {@linkplain SelectionSpecification#addOrdering sorting}
* and {@linkplain SelectionSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain SelectionSpecification#sort sorting}
* and {@linkplain SelectionSpecification#restrict restrictions}.
* This is effectively the same as calling {@linkplain #create(Class, String)}
* with {@code "from {rootEntityType}"} as the HQL.
*
Expand All @@ -174,8 +175,8 @@ static <T> SelectionSpecification<T> create(Class<T> rootEntityType) {
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain SelectionQuery} based on a base HQL statement,
* allowing the addition of {@linkplain SelectionSpecification#addOrdering sorting}
* and {@linkplain SelectionSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain SelectionSpecification#sort sorting}
* and {@linkplain SelectionSpecification#restrict restrictions}.
*
* @param hql The base HQL query.
* @param resultType The result type which will ultimately be returned from the {@linkplain SelectionQuery}
Expand All @@ -193,8 +194,8 @@ static <T> SelectionSpecification<T> create(Class<T> resultType, String hql) {
/**
* Returns a specification reference which can be used to programmatically,
* iteratively build a {@linkplain SelectionQuery} for the given criteria query,
* allowing the addition of {@linkplain SelectionSpecification#addOrdering sorting}
* and {@linkplain SelectionSpecification#addRestriction restrictions}.
* allowing the addition of {@linkplain SelectionSpecification#sort sorting}
* and {@linkplain SelectionSpecification#restrict restrictions}.
*
* @param criteria The criteria query
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public MutationSpecificationImpl(CriteriaDelete<T> criteriaQuery) {
}

@Override
public MutationSpecification<T> addRestriction(Restriction<T> restriction) {
public MutationSpecification<T> restrict(Restriction<T> restriction) {
specifications.add( (sqmStatement, mutationTargetRoot) -> {
final SqmPredicate sqmPredicate = (SqmPredicate) restriction.toPredicate(
mutationTargetRoot,
Expand All @@ -74,7 +74,7 @@ public MutationSpecification<T> addRestriction(Restriction<T> restriction) {
}

@Override
public MutationSpecification<T> addAugmentation(Augmentation<T> augmentation) {
public MutationSpecification<T> augment(Augmentation<T> augmentation) {
specifications.add( (sqmStatement, mutationTargetRoot) ->
augmentation.augment( sqmStatement.nodeBuilder(), sqmStatement, mutationTargetRoot ) );
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SelectionSpecificationImpl(CriteriaQuery<T> criteriaQuery) {
}

@Override
public SelectionSpecification<T> addRestriction(Restriction<T> restriction) {
public SelectionSpecification<T> restrict(Restriction<T> restriction) {
specifications.add( (sqmStatement, root) -> {
final SqmPredicate sqmPredicate = SqmUtil.restriction( sqmStatement, resultType, restriction );
sqmStatement.getQuerySpec().applyPredicate( sqmPredicate );
Expand All @@ -73,28 +73,28 @@ public SelectionSpecification<T> addRestriction(Restriction<T> restriction) {
}

@Override
public SelectionSpecification<T> addAugmentation(Augmentation<T> augmentation) {
public SelectionSpecification<T> augment(Augmentation<T> augmentation) {
specifications.add( (sqmStatement, root) ->
augmentation.augment( sqmStatement.nodeBuilder(), sqmStatement, root ) );
return this;
}

@Override
public SelectionSpecification<T> addFetching(Path<T, ?> fetchPath) {
public SelectionSpecification<T> fetch(Path<T, ?> fetchPath) {
specifications.add( (sqmStatement, root) -> fetchPath.fetch( root ) );
return this;
}

@Override
public SelectionSpecification<T> addOrdering(Order<T> order) {
public SelectionSpecification<T> sort(Order<T> order) {
specifications.add( (sqmStatement, root) -> {
addOrder( order, sqmStatement );
} );
return this;
}

@Override
public final SelectionSpecification<T> setOrdering(Order<T> order) {
public final SelectionSpecification<T> resort(Order<T> order) {
specifications.add( (sqmStatement, root) -> {
sqmStatement.getQuerySpec().setOrderByClause( new SqmOrderByClause() );
addOrder( order, sqmStatement );
Expand All @@ -103,7 +103,7 @@ public final SelectionSpecification<T> setOrdering(Order<T> order) {
}

@Override
public final SelectionSpecification<T> setOrdering(List<Order<T>> orders) {
public final SelectionSpecification<T> resort(List<Order<T>> orders) {
specifications.add( (sqmStatement, root) -> {
sqmStatement.getQuerySpec().setOrderByClause( new SqmOrderByClause() );
orders.forEach( order -> addOrder( order, sqmStatement ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
* the root entity type of the query.
* <pre>
* SelectionSpecification.create(Book.class)
* .addRestriction(from(Book.class).to(Book_.publisher).to(Publisher_.name)
* .restrict(from(Book.class).to(Book_.publisher).to(Publisher_.name)
* .equalTo("Manning"))
* .fetch(from(Book.class).to(Book_.publisher))
* .createQuery(session)
* .getResultList()
* </pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* {@link SelectionQuery#addRestriction(Restriction)}.
* <pre>
* SelectionSpecification.create(Book.class)
* .addRestriction(Restriction.like(Book_.title, "%Hibernate%", false))
* .addRestriction(Restriction.greaterThan(Book_.pages, 100))
* .setOrder(Order.desc(Book_.title))
* .restrict(Restriction.like(Book_.title, "%Hibernate%", false))
* .restrict(Restriction.greaterThan(Book_.pages, 100))
* .sort(Order.desc(Book_.title))
* .createQuery(session)
* .getResultList();
* </pre>
Expand All @@ -50,7 +50,7 @@
*
* @see org.hibernate.query.programmatic.SelectionSpecification
* @see org.hibernate.query.programmatic.MutationSpecification
* @see org.hibernate.query.programmatic.QuerySpecification#addRestriction(Restriction)
* @see org.hibernate.query.programmatic.QuerySpecification#restrict(Restriction)
*
* @see Path
* @see Order
Expand Down
Loading