Skip to content

Commit

Permalink
remove unnecessary restriction on @query with CursoredPage
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Mar 20, 2024
1 parent 4c1bcf9 commit 9385415
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 28 deletions.
26 changes: 0 additions & 26 deletions api/src/main/java/jakarta/data/page/CursoredPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,6 @@
* existing entities are modified or if an entity is re-added with different
* sort criteria after having previously been removed.</p>
*
* <h2>Cursor-based Pagination with {@code @Query}</h2>
*
* <p>Cursor-based pagination involves generating and appending additional
* restrictions involving the key fields to the {@code WHERE} clause of the
* query. For this to be possible, a user-provided JDQL or JPQL query must
* end with a {@code WHERE} clause to which additional conditions may be
* appended without otherwise changing the semantics of the query:</p>
* <ul>
* <li>The entire conditional expression of the {@code WHERE} clause must
* be enclosed in parentheses.
* <li>Sorting criteria must be specified independently of the user-provided
* query, either via the {@link OrderBy} annotation or, or by passing
* {@link Sort} criteria within the {@linkplain PageRequest#sorts() page
* request}.
* </ul>
* <p>For example:</p>
*
* <pre>
* &#64;Query("WHERE (ordersPlaced &gt;= ?1 OR totalSpent &gt;= ?2)")
* &#64;OrderBy("zipcode")
* &#64;OrderBy("birthYear")
* &#64;OrderBy("id")
* CursoredPage&lt;Customer&gt; getTopBuyers(int minOrders, float minSpent,
* {@code PageRequest<Customer>} pageRequest);
* </pre>
*
* <p>Only queries which return entities may be used with cursor-based pagination
* because cursors are created from the entity attribute values that
* form the unique key.</p>
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/jakarta/data/repository/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* {@code @Repository}
* public interface Products extends BasicRepository{@code <Product, String>} {
*
* {@code @Query("WHERE (p.length * p.width * p.height <= :maxVolume)")}
* {@code @Query("WHERE length * width * height <= :maxVolume")}
* {@code Page<Product>} freeShippingEligible({@code @Param}("maxVolume") float volumeLimit,
* {@code PageRequest<?>} pageRequest);
*
Expand Down
2 changes: 1 addition & 1 deletion spec/src/main/asciidoc/repository.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ Here is an example where an application uses `@Query` to provide a partial query
----
@Repository
public interface CustomerRepository extends BasicRepository<Customer, Long> {
@Query("WHERE (o.totalSpent / o.totalPurchases > ?1)")
@Query("WHERE totalSpent / totalPurchases > ?1")
CursoredPage<Customer> withAveragePurchaseAbove(float minimum, PageRequest<Customer> pageRequest);
}
----
Expand Down

0 comments on commit 9385415

Please sign in to comment.