mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
Fix beanCache order by & clear did not work
(cherry picked from commit 4dee827fda)
This commit is contained in:
1 parent
2aba1835f1
commit
8c800e992d
2 files changed
+17
-3
No files matched your search
@@ -524,7 +524,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
|||||||
}
|
}
|
||||||
if (result instanceof BeanList) {
|
if (result instanceof BeanList) {
|
||||||
OrderBy<T> orderBy = query.getOrderBy();
|
OrderBy<T> orderBy = query.getOrderBy();
|
||||||
if (orderBy != null) {
|
if (orderBy != null && !orderBy.isEmpty()) {
|
||||||
// in memory sort after merging the cache hits with the DB hits
|
// in memory sort after merging the cache hits with the DB hits
|
||||||
beanDescriptor.sort(((BeanList<T>) result).getActualList(), orderBy.toStringFormat());
|
beanDescriptor.sort(((BeanList<T>) result).getActualList(), orderBy.toStringFormat());
|
||||||
}
|
}
|
||||||
@@ -543,7 +543,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
|||||||
@Override
|
@Override
|
||||||
public List<T> beanCacheHits() {
|
public List<T> beanCacheHits() {
|
||||||
OrderBy<T> orderBy = query.getOrderBy();
|
OrderBy<T> orderBy = query.getOrderBy();
|
||||||
if (orderBy != null) {
|
if (orderBy != null && !orderBy.isEmpty()) {
|
||||||
beanDescriptor.sort(cacheBeans, orderBy.toStringFormat());
|
beanDescriptor.sort(cacheBeans, orderBy.toStringFormat());
|
||||||
}
|
}
|
||||||
return cacheBeans;
|
return cacheBeans;
|
||||||
@@ -552,7 +552,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
|||||||
@Override
|
@Override
|
||||||
public <K> Map<K, T> beanCacheHitsAsMap() {
|
public <K> Map<K, T> beanCacheHitsAsMap() {
|
||||||
OrderBy<T> orderBy = query.getOrderBy();
|
OrderBy<T> orderBy = query.getOrderBy();
|
||||||
if (orderBy != null) {
|
if (orderBy != null && !orderBy.isEmpty()) {
|
||||||
beanDescriptor.sort(cacheBeans, orderBy.toStringFormat());
|
beanDescriptor.sort(cacheBeans, orderBy.toStringFormat());
|
||||||
}
|
}
|
||||||
return cacheBeansToMap();
|
return cacheBeansToMap();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.ebean.OrderBy;
|
|||||||
import io.ebean.Query;
|
import io.ebean.Query;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.Order;
|
import org.tests.model.basic.Order;
|
||||||
|
import org.tests.model.basic.OrderDetail;
|
||||||
import org.tests.model.basic.ResetBasicData;
|
import org.tests.model.basic.ResetBasicData;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
@@ -37,5 +38,18 @@ public class TestOrderByClear extends BaseTestCase {
|
|||||||
assertTrue(sql.contains("order by t0.ship_date"));
|
assertTrue(sql.contains("order by t0.ship_date"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithCache() {
|
||||||
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
Query<OrderDetail> query = DB.find(OrderDetail.class).where().idIn(1,2,3).query();
|
||||||
|
query.setUseCache(true);
|
||||||
|
query.findList();
|
||||||
|
query.order().asc("cretime").findList(); // hit cache
|
||||||
|
query.order().clear();
|
||||||
|
query.findList(); // hit cache again
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user