mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1269 - Paging queries should not ALWAYS append an order by ID ... but only when the order by is empty
This commit is contained in:
1 parent
ec7b376612
commit
8ee68ac5e1
8 files changed
+38
-24
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.OrderBy;
|
||||
import io.ebean.PersistenceContextScope;
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.Query;
|
||||
@@ -3055,14 +3054,10 @@ public class BeanDescriptor<T> implements BeanType<T> {
|
||||
public void appendOrderById(SpiQuery<T> query) {
|
||||
|
||||
if (idProperty != null && !idProperty.isEmbedded()) {
|
||||
OrderBy<T> orderBy = query.getOrderBy();
|
||||
if (orderBy == null || orderBy.isEmpty()) {
|
||||
SpiRawSql rawSql = query.getRawSql();
|
||||
if (rawSql != null) {
|
||||
query.order(rawSql.getSql().getOrderBy());
|
||||
}
|
||||
query.order().asc(idProperty.getName());
|
||||
} else if (!orderBy.containsProperty(idProperty.getName())) {
|
||||
SpiRawSql rawSql = query.getRawSql();
|
||||
if (rawSql != null) {
|
||||
query.order(rawSql.getSql().getOrderBy());
|
||||
} else {
|
||||
query.order().asc(idProperty.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ public class CQueryEngine {
|
||||
*/
|
||||
private <T> void prepareForPaging(OrmQueryRequest<T> request) {
|
||||
SpiQuery<T> query = request.getQuery();
|
||||
if (!query.isDistinct() && (query.getMaxRows() > 1 || query.getFirstRow() > 0)) {
|
||||
if (query.checkPagingOrderBy()) {
|
||||
request.getBeanDescriptor().appendOrderById(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1372,6 +1372,15 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPagingOrderBy() {
|
||||
return (maxRows > 1 || firstRow > 0) && !distinct && orderByIsEmpty();
|
||||
}
|
||||
|
||||
private boolean orderByIsEmpty() {
|
||||
return orderBy == null || orderBy.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderBy<T> getOrderBy() {
|
||||
return orderBy;
|
||||
|
||||
Reference in new issue
Block a user