mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1215 - ENH: Add Query setBeanCacheMode(CacheMode) ... with a view to it replacing the existing setUseCache(boolean) and setLoadBeanCache(boolean)
This commit is contained in:
@@ -129,7 +129,7 @@ public abstract class BaseTestCase {
|
||||
protected void loadCountryCache() {
|
||||
|
||||
Ebean.find(Country.class)
|
||||
.setLoadBeanCache(true)
|
||||
.setBeanCacheMode(CacheMode.RECACHE)
|
||||
.findList();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -23,7 +24,7 @@ public class TestLazyLoadInCache extends BaseTestCase {
|
||||
|
||||
Map<Integer, Customer> map = Ebean.find(Customer.class)
|
||||
.select("id, name")
|
||||
.setLoadBeanCache(true)
|
||||
.setBeanCacheMode(CacheMode.RECACHE)
|
||||
.setReadOnly(true)
|
||||
.orderBy().asc("id")
|
||||
.findMap();
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderDetail;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -24,7 +25,7 @@ public class TestReadOnlyPropagation extends BaseTestCase {
|
||||
|
||||
Order order = Ebean.find(Order.class)
|
||||
.setAutoTune(false)
|
||||
.setUseCache(false)
|
||||
.setBeanCacheMode(CacheMode.OFF)
|
||||
.setReadOnly(true)
|
||||
.setId(1)
|
||||
.findOne();
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package org.tests.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.SqlUpdate;
|
||||
import io.ebean.Update;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import io.ebean.cache.ServerCacheManager;
|
||||
import io.ebeaninternal.server.cache.CachedManyIds;
|
||||
import org.tests.model.basic.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.OCachedBean;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderDetail;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -33,7 +40,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
||||
custCache.clear();
|
||||
custManyIdsCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setAutoTune(false).setLoadBeanCache(true)
|
||||
List<Customer> list = Ebean.find(Customer.class).setAutoTune(false).setBeanCacheMode(CacheMode.RECACHE)
|
||||
.order().asc("id").findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 1);
|
||||
|
||||
+4
-3
@@ -1,14 +1,15 @@
|
||||
package org.tests.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class TestCacheCustomer extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setAutoTune(false).setLoadBeanCache(true)
|
||||
List<Customer> list = Ebean.find(Customer.class).setAutoTune(false).setBeanCacheMode(CacheMode.RECACHE)
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 1);
|
||||
|
||||
+6
-3
@@ -1,16 +1,19 @@
|
||||
package org.tests.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import io.ebean.cache.ServerCacheStatistics;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestCacheNaturalId extends BaseTestCase {
|
||||
|
||||
@@ -21,7 +24,7 @@ public class TestCacheNaturalId extends BaseTestCase {
|
||||
|
||||
ServerCache contactCache = Ebean.getServerCacheManager().getBeanCache(Contact.class);
|
||||
|
||||
List<Contact> list = Ebean.find(Contact.class).setLoadBeanCache(true).findList();
|
||||
List<Contact> list = Ebean.find(Contact.class).setBeanCacheMode(CacheMode.RECACHE).findList();
|
||||
|
||||
assertTrue(contactCache.size() > 0);
|
||||
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package org.tests.model.basic.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import io.ebean.cache.ServerCacheManager;
|
||||
@@ -77,7 +78,7 @@ public class TestCacheViaComplexNaturalKey extends BaseTestCase {
|
||||
private void loadSomeIntoCache() {
|
||||
|
||||
Ebean.find(OCachedNatKeyBean.class)
|
||||
.setLoadBeanCache(true)
|
||||
.setBeanCacheMode(CacheMode.RECACHE)
|
||||
.where().le("sku", "2")
|
||||
.findList();
|
||||
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package org.tests.model.basic.cache;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Pairs;
|
||||
import io.ebean.cache.ServerCache;
|
||||
@@ -81,7 +82,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
private void loadSomeIntoCache() {
|
||||
|
||||
Ebean.find(OCachedNatKeyBean3.class)
|
||||
.setLoadBeanCache(true)
|
||||
.setBeanCacheMode(CacheMode.RECACHE)
|
||||
.where()
|
||||
.ge("sku", "2")
|
||||
.eq("store", "def")
|
||||
@@ -302,7 +303,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
|
||||
.where()
|
||||
.eq("store", "def")
|
||||
.inPairs(pairs)
|
||||
.setUseCache(true)
|
||||
.setBeanCacheMode(CacheMode.ON)
|
||||
.orderBy("sku desc")
|
||||
.findList();
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.Ebean;
|
||||
import org.tests.model.basic.Article;
|
||||
import org.tests.model.basic.Section;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Article;
|
||||
import org.tests.model.basic.Section;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,7 +32,7 @@ public class TestQueryFindReadOnly extends BaseTestCase {
|
||||
Section s2 = ar1sections.get(0);
|
||||
Assert.assertTrue("readonly cascading", Ebean.getBeanState(s2).isReadOnly());
|
||||
|
||||
Ebean.find(Article.class).setLoadBeanCache(true).findList();
|
||||
Ebean.find(Article.class).setBeanCacheMode(CacheMode.RECACHE).findList();
|
||||
|
||||
Article ar0 = Ebean.find(Article.class, a0.getId());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user