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

This commit is contained in:
Robin Bygrave committed 2015-09-14 11:29:38 +12:00
1 parent ec4f655312
commit 47829f3985
6 files changed
+179 -80

No files matched your search

@@ -1,5 +1,6 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.OrderBy;
import com.avaje.ebean.SqlUpdate;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.ValuePair;
@@ -2098,6 +2099,26 @@ public class BeanDescriptor<T> implements MetaBeanInfo, SpiBeanType<T> {
}
}
/**
* Appends the Id property to the OrderBy clause if it is not believed
* to be already contained in the order by.
* <p>
* This is primarily used for paging queries to ensure that an order by clause is provided and that the order by
* provides unique ordering of the rows (so that the paging is predicable).
* </p>
*/
public void appendOrderById(SpiQuery<T> query) {
if (idProperty != null) {
OrderBy<T> orderBy = query.getOrderBy();
if (orderBy == null || orderBy.isEmpty()) {
query.order().asc(idProperty.getName());
} else if (!orderBy.containsProperty(idProperty.getName())){
query.order().asc(idProperty.getName());
}
}
}
/**
* All the BeanPropertyAssocOne that are not embedded. These are effectively
* joined beans. For ManyToOne and OneToOne associations.