#410 - Require findPagedList() query to specify an order by clause - throw exception if no order by supplied

This commit is contained in:
Robin Bygrave
2015-09-14 10:39:41 +12:00
parent 04fda0a6b4
commit ec4f655312
4 changed files with 134 additions and 3 deletions
@@ -1362,8 +1362,15 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
@Override
public <T> PagedList<T> findPagedList(Query<T> query, Transaction transaction, int pageIndex, int pageSize) {
return new LimitOffsetPagedList<T>(this, (SpiQuery<T>)query, pageIndex, pageSize);
SpiQuery spiQuery = (SpiQuery<T>)query;
OrderBy orderBy = spiQuery.getOrderBy();
if (orderBy == null || orderBy.isEmpty()) {
// add a default order by for paging queries
BeanDescriptor<T> desc = beanDescriptorManager.getBeanDescriptor(spiQuery.getBeanType());
query.orderBy(desc.getDefaultOrderBy());
}
return new LimitOffsetPagedList<T>(this, spiQuery, pageIndex, pageSize);
}
public <T> void findEach(Query<T> query, QueryEachConsumer<T> consumer, Transaction t) {