[clarification]: Keyset pagination, what should happen when the order is not defined?
otaviojava opened this issue · 4 comments
Specification
I need clarification on ...
At the specification, there is this point:
Sort criteria must be provided and should be minimal.
But what happens if the user does not inform any Sort element?
Using the same spec example:
@Repository
public interface Products extends CrudRepository<Product, Long> {
CursoredPage<Product> findByNameLike(String namePattern, PageRequest<Product> pageRequest);
}
In this case, I will remove the Order method:
float priceMidpoint = 50.0f;
PageRequest<Product> pageRequest =
//Order.by(_Product.price.asc(), _Product.id.asc()) removed, please, ignore if it will compile or not
PageRequest
.pageSize(10)
.afterKey(priceMidpoint, 0L);
CursoredPage<Product> moreExpensive =
products.findByNameLike(pattern, pageRequest);
Additional information
No response
PageRequest<Product> pageRequest = //Order.by(_Product.price.asc(), _Product.id.asc()) removed, please, ignore if it will compile or not PageRequest .pageSize(10) .afterKey(priceMidpoint, 0L); CursoredPage<Product> moreExpensive = products.findByNameLike(pattern, pageRequest);
The example you gave is a user error for two reasons.
One reason is that it violates the rule from the specification that you cited:
Sort criteria must be provided and should be minimal.
The second reason is there is also a requirement for the size of the sort criteria to exactly match the number of key components of the cursor. In your example, you have 2 key components supplied to afterKey
but the size of the sort criteria is 0.
The example usage can be rejected on the basis of either of these.
Thanks, @njr-11; my question is, what exception should I throw?
IllegalStateException
UnsupportedOperationException
DataException
- a Jakarta Data provider
The specification is not clear at this point.
I would recommend IllegalArugmentException
because the user has supplied a PageRequest
argument that is not appropriate for cursor-based pagination -- it has no Sorts and its number of key components does not match the amount of sort criteria.
I agree, that was my thought too.