mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#684 - Refactor - rename @CacheStrategy to @Cache ... require explicit enableQueryCache=true for query cache use
This commit is contained in:
@@ -2,9 +2,11 @@ package com.avaje.ebeaninternal.server.cache;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.transaction.DefaultPersistenceContext;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -50,7 +52,7 @@ public class CacheBeanDataTest extends BaseTestCase {
|
||||
|
||||
Customer newCustomer = new Customer();
|
||||
newCustomer.setId(c.getId());
|
||||
CachedBeanDataToBean.load(desc, (EntityBean) newCustomer, cacheData);
|
||||
CachedBeanDataToBean.load(desc, (EntityBean) newCustomer, cacheData, new DefaultPersistenceContext());
|
||||
|
||||
assertEquals(c.getId(), newCustomer.getId());
|
||||
assertEquals(c.getName(), newCustomer.getName());
|
||||
@@ -91,9 +93,11 @@ public class CacheBeanDataTest extends BaseTestCase {
|
||||
|
||||
CachedBeanData addressCacheData = (CachedBeanData) addressBeanProperty.getCacheDataValue((EntityBean) person);
|
||||
|
||||
PersistenceContext context = new DefaultPersistenceContext();
|
||||
|
||||
EPerson newPersonCheck = new EPerson();
|
||||
newPersonCheck.setId(98989L);
|
||||
addressBeanProperty.setCacheDataValue((EntityBean) newPersonCheck, addressCacheData);
|
||||
addressBeanProperty.setCacheDataValue((EntityBean) newPersonCheck, addressCacheData, context);
|
||||
|
||||
EAddress newAddress = newPersonCheck.getAddress();
|
||||
assertEquals(address.getStreet(), newAddress.getStreet());
|
||||
@@ -105,7 +109,7 @@ public class CacheBeanDataTest extends BaseTestCase {
|
||||
|
||||
assertNotNull(cacheData);
|
||||
|
||||
EPerson newPerson = (EPerson)desc.cacheEmbeddedBeanLoad(cacheData);
|
||||
EPerson newPerson = (EPerson)desc.cacheEmbeddedBeanLoad(cacheData, context);
|
||||
|
||||
assertNotNull(newPerson.getId());
|
||||
assertNotNull(newPerson.getName());
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@ import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.transaction.DefaultPersistenceContext;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Car;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
@@ -51,7 +52,7 @@ public class CachedBeanDataFromBeanTest extends BaseTestCase {
|
||||
|
||||
Car newCar = new Car();
|
||||
EntityBean entityBean = (EntityBean)newCar;
|
||||
CachedBeanDataToBean.load(carDesc, entityBean, cacheData);
|
||||
CachedBeanDataToBean.load(carDesc, entityBean, cacheData, new DefaultPersistenceContext());
|
||||
|
||||
assertEquals(newCar.getId(), car.getId());
|
||||
assertEquals(newCar.getDriver(), car.getDriver());
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.transaction.DefaultPersistenceContext;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import com.avaje.tests.model.basic.TBytesOnly;
|
||||
@@ -82,7 +83,7 @@ public class CachedBeanDataSerializeTest extends BaseTestCase {
|
||||
assertEquals(read.getData(), extract.getData());
|
||||
|
||||
Customer loadCustomer = new Customer();
|
||||
CachedBeanDataToBean.load(desc, (EntityBean)loadCustomer, read);
|
||||
CachedBeanDataToBean.load(desc, (EntityBean)loadCustomer, read, new DefaultPersistenceContext());
|
||||
|
||||
assertEquals(loadCustomer.getVersion(), customer.getVersion());
|
||||
assertEquals(loadCustomer.getId(), customer.getId());
|
||||
@@ -113,7 +114,7 @@ public class CachedBeanDataSerializeTest extends BaseTestCase {
|
||||
assertTrue(Arrays.equals(bean.getContent(), extraContent));
|
||||
|
||||
TBytesOnly loadBean= new TBytesOnly();
|
||||
CachedBeanDataToBean.load(desc, (EntityBean)loadBean, read);
|
||||
CachedBeanDataToBean.load(desc, (EntityBean)loadBean, read, new DefaultPersistenceContext());
|
||||
|
||||
assertEquals(loadBean.getId(), bean.getId());
|
||||
assertTrue(Arrays.equals(loadBean.getContent(), bean.getContent()));
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BeanDescriptorTest extends BaseTestCase {
|
||||
@Test
|
||||
public void createReference() {
|
||||
|
||||
Customer bean = customerDesc.createReference(null, 42);
|
||||
Customer bean = customerDesc.createReference(null, 42, null);
|
||||
assertThat(bean.getId()).isEqualTo(42);
|
||||
assertThat(server().getBeanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
@@ -26,14 +26,14 @@ public class BeanDescriptorTest extends BaseTestCase {
|
||||
@Test
|
||||
public void createReference_whenReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.TRUE, 42);
|
||||
Customer bean = customerDesc.createReference(Boolean.TRUE, 42, null);
|
||||
assertThat(server().getBeanState(bean).isReadOnly()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_whenNotReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, 42);
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, 42, null);
|
||||
assertThat(server().getBeanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ public class TunedQueryInfoTest extends BaseTestCase {
|
||||
|
||||
ServerCacheManager serverCacheManager = Ebean.getServer(null).getServerCacheManager();
|
||||
serverCacheManager.clearAll();
|
||||
serverCacheManager.setCaching(Order.class, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,61 +1,66 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestManyLazyLoad extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testLazyLoadRef() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).order().asc("id").findList();
|
||||
Assert.assertTrue(list.size()+" > 0", list.size() > 0);
|
||||
|
||||
// just use the first one
|
||||
Order order = list.get(0);
|
||||
|
||||
// get it as a reference
|
||||
Order order1 = Ebean.getReference(Order.class, order.getId());
|
||||
Assert.assertNotNull(order1);
|
||||
|
||||
Date orderDate = order1.getOrderDate();
|
||||
Assert.assertNotNull(orderDate);
|
||||
|
||||
List<OrderDetail> details = order1.getDetails();
|
||||
|
||||
// lazy load the details
|
||||
int sz = details.size();
|
||||
Assert.assertTrue(sz+" > 0", sz > 0);
|
||||
|
||||
Order o = details.get(0).getOrder();
|
||||
Assert.assertTrue("same instance", o == order1);
|
||||
|
||||
@Test
|
||||
public void testLazyLoadRef() throws InterruptedException {
|
||||
|
||||
// change order... list before a scalar property
|
||||
Order order2 = Ebean.getReference(Order.class, order.getId());
|
||||
Assert.assertNotNull(order2);
|
||||
|
||||
List<OrderDetail> details2 = order2.getDetails();
|
||||
|
||||
// lazy load the details
|
||||
int sz2 = details2.size();
|
||||
Assert.assertTrue(sz2+" > 0", sz2 > 0);
|
||||
|
||||
Order o2 = details2.get(0).getOrder();
|
||||
Assert.assertTrue("same instance", o2 == order2);
|
||||
ResetBasicData.reset();
|
||||
|
||||
awaitL2Cache();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).order().asc("id").findList();
|
||||
assertTrue(list.size() + " > 0", list.size() > 0);
|
||||
|
||||
// just use the first one
|
||||
Order order = list.get(0);
|
||||
|
||||
// get it as a reference
|
||||
Order order1 = Ebean.getReference(Order.class, order.getId());
|
||||
assertNotNull(order1);
|
||||
|
||||
Date orderDate = order1.getOrderDate();
|
||||
assertNotNull(orderDate);
|
||||
|
||||
List<OrderDetail> details = order1.getDetails();
|
||||
|
||||
// lazy load the details
|
||||
int sz = details.size();
|
||||
assertTrue(sz + " > 0", sz > 0);
|
||||
|
||||
OrderDetail orderDetail = details.get(0);
|
||||
Order o = orderDetail.getOrder();
|
||||
assertSame(o, order1);
|
||||
|
||||
// load detail into cache
|
||||
Ebean.find(OrderDetail.class, orderDetail.getId());
|
||||
|
||||
// change order... list before a scalar property
|
||||
Order order2 = Ebean.getReference(Order.class, order.getId());
|
||||
assertNotNull(order2);
|
||||
|
||||
List<OrderDetail> details2 = order2.getDetails();
|
||||
|
||||
// lazy load the details
|
||||
int sz2 = details2.size();
|
||||
assertTrue(sz2 + " > 0", sz2 > 0);
|
||||
|
||||
Order o2 = details2.get(0).getOrder();
|
||||
assertSame(o2, order2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ public class TestQueryWithCache extends BaseTestCase {
|
||||
CacheOptions cacheOptions = beanDescriptor.getCacheOptions();
|
||||
|
||||
Assert.assertNotNull(cacheOptions);
|
||||
Assert.assertTrue(cacheOptions.isUseCache());
|
||||
Assert.assertTrue(cacheOptions.isReadOnly());
|
||||
Assert.assertTrue(beanDescriptor.isCacheSharableBeans());
|
||||
|
||||
|
||||
@@ -28,9 +28,6 @@ public class TestBatchLazyWithCacheHits extends BaseTestCase {
|
||||
inserted.add(insert(names[i]));
|
||||
}
|
||||
|
||||
ServerCacheManager serverCacheManager = Ebean.getServerCacheManager();
|
||||
serverCacheManager.setCaching(UUOne.class, true);
|
||||
|
||||
UUOne b = Ebean.find(UUOne.class)
|
||||
.setId(inserted.get(1).getId())
|
||||
.setUseCache(true)
|
||||
|
||||
@@ -12,28 +12,33 @@ import com.avaje.ebean.cache.ServerCacheStatistics;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestQueryCacheCountry extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
awaitL2Cache();
|
||||
|
||||
ServerCache queryCache = Ebean.getServerCacheManager().getQueryCache(Country.class);
|
||||
queryCache.clear();
|
||||
|
||||
ServerCache beanCache = Ebean.getServerCacheManager().getBeanCache(Country.class);
|
||||
beanCache.clear();
|
||||
|
||||
Assert.assertEquals(0, queryCache.getStatistics(false).getSize());
|
||||
assertEquals(0, queryCache.getStatistics(false).getSize());
|
||||
|
||||
List<Country> countryList0 = Ebean.find(Country.class)
|
||||
.setUseQueryCache(true)
|
||||
.order().asc("name")
|
||||
.findList();
|
||||
|
||||
Assert.assertEquals(1, queryCache.getStatistics(false).getSize());
|
||||
Assert.assertTrue(countryList0.size() > 0);
|
||||
assertEquals(1, queryCache.getStatistics(false).getSize());
|
||||
assertTrue(countryList0.size() > 0);
|
||||
|
||||
List<Country> countryList1 = Ebean.find(Country.class)
|
||||
.setUseQueryCache(true)
|
||||
@@ -41,8 +46,8 @@ public class TestQueryCacheCountry extends BaseTestCase {
|
||||
.findList();
|
||||
|
||||
ServerCacheStatistics statistics = queryCache.getStatistics(false);
|
||||
Assert.assertEquals(1, statistics.getSize());
|
||||
Assert.assertEquals(1, statistics.getHitCount());
|
||||
assertEquals(1, statistics.getSize());
|
||||
assertEquals(1, statistics.getHitCount());
|
||||
Assert.assertSame(countryList1, countryList0);
|
||||
|
||||
Country nz = Ebean.find(Country.class, "NZ");
|
||||
@@ -51,7 +56,7 @@ public class TestQueryCacheCountry extends BaseTestCase {
|
||||
awaitL2Cache();
|
||||
|
||||
statistics = queryCache.getStatistics(false);
|
||||
Assert.assertEquals(0, statistics.getSize());
|
||||
assertEquals(0, statistics.getSize());
|
||||
|
||||
List<Country> countryList2 = Ebean.find(Country.class)
|
||||
.setUseQueryCache(true)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.CacheBeanTuning;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
@@ -10,7 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@CacheBeanTuning(maxSecsToLive = 45)
|
||||
@Entity
|
||||
public class Article extends BasicDomain {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
import com.avaje.ebean.annotation.DocEmbedded;
|
||||
@@ -17,136 +17,134 @@ import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
@DocStore
|
||||
@Index(columnNames = {"last_name","first_name"})
|
||||
@Index(columnNames = {"last_name", "first_name"})
|
||||
@ChangeLog
|
||||
@Entity
|
||||
@CacheStrategy(naturalKey="email")
|
||||
@Cache(naturalKey = "email")
|
||||
public class Contact {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Id
|
||||
int id;
|
||||
|
||||
@Id
|
||||
int id;
|
||||
String firstName;
|
||||
String lastName;
|
||||
|
||||
String firstName;
|
||||
String lastName;
|
||||
String phone;
|
||||
String mobile;
|
||||
String email;
|
||||
|
||||
String phone;
|
||||
String mobile;
|
||||
String email;
|
||||
@DocEmbedded(doc = "id,name")
|
||||
@ManyToOne(optional = false)
|
||||
Customer customer;
|
||||
|
||||
@DocEmbedded(doc="id,name")
|
||||
@ManyToOne(optional=false)
|
||||
Customer customer;
|
||||
|
||||
@ManyToOne(optional=true)
|
||||
ContactGroup group;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<ContactNote> notes;
|
||||
@ManyToOne(optional = true)
|
||||
ContactGroup group;
|
||||
|
||||
@CreatedTimestamp
|
||||
Timestamp cretime;
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<ContactNote> notes;
|
||||
|
||||
@Version
|
||||
Timestamp updtime;
|
||||
@CreatedTimestamp
|
||||
Timestamp cretime;
|
||||
|
||||
@Version
|
||||
Timestamp updtime;
|
||||
|
||||
|
||||
public Contact(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public Contact(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Contact() {
|
||||
public Contact() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Timestamp getUpdtime() {
|
||||
return updtime;
|
||||
}
|
||||
public Timestamp getUpdtime() {
|
||||
return updtime;
|
||||
}
|
||||
|
||||
public void setUpdtime(Timestamp updtime) {
|
||||
this.updtime = updtime;
|
||||
}
|
||||
public void setUpdtime(Timestamp updtime) {
|
||||
this.updtime = updtime;
|
||||
}
|
||||
|
||||
public Timestamp getCretime() {
|
||||
return cretime;
|
||||
}
|
||||
public Timestamp getCretime() {
|
||||
return cretime;
|
||||
}
|
||||
|
||||
public void setCretime(Timestamp cretime) {
|
||||
this.cretime = cretime;
|
||||
}
|
||||
public void setCretime(Timestamp cretime) {
|
||||
this.cretime = cretime;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
public Customer getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public ContactGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
public void setCustomer(Customer customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public void setGroup(ContactGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
public ContactGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public List<ContactNote> getNotes() {
|
||||
return notes;
|
||||
}
|
||||
public void setGroup(ContactGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void setNotes(List<ContactNote> notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
public List<ContactNote> getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(List<ContactNote> notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.CacheBeanTuning;
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.ChangeLogInsertMode;
|
||||
@@ -18,7 +18,7 @@ import javax.validation.constraints.Size;
|
||||
@DocStore
|
||||
@ReadAudit
|
||||
@ChangeLog(inserts = ChangeLogInsertMode.INCLUDE)
|
||||
@CacheStrategy(readOnly = true)
|
||||
@Cache(readOnly = true, enableQueryCache = true)
|
||||
@CacheBeanTuning(maxSize = 500)
|
||||
@Entity
|
||||
@Table(name = "o_country")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.ChangeLogInsertMode;
|
||||
import com.avaje.ebean.annotation.DbComment;
|
||||
@@ -26,6 +27,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
/**
|
||||
* Customer entity bean.
|
||||
*/
|
||||
@Cache(enableQueryCache = true)
|
||||
@DocStore
|
||||
@ChangeLog(inserts = ChangeLogInsertMode.EXCLUDE, updatesThatInclude = {"name","status"})
|
||||
@Entity
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.ReadAudit;
|
||||
import com.avaje.ebean.annotation.WhenCreated;
|
||||
@@ -13,6 +14,7 @@ import javax.persistence.Version;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Cache(enableQueryCache = true)
|
||||
@ReadAudit
|
||||
@ChangeLog(updatesThatInclude = {"name","shortDescription"})
|
||||
@Entity
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@@ -7,6 +9,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Cache(enableQueryCache = true)
|
||||
@Entity
|
||||
@Table(name = "e_basicver")
|
||||
public class EBasicVer {
|
||||
|
||||
@@ -4,9 +4,9 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
@CacheStrategy(readOnly = true, useBeanCache = true)
|
||||
@Cache(readOnly = true)
|
||||
@Entity
|
||||
@Table(name="feature_desc")
|
||||
public class FeatureDescription {
|
||||
|
||||
@@ -10,12 +10,12 @@ import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
/**
|
||||
* Cached bean for testing caching implementation.
|
||||
*/
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@Entity
|
||||
@Table(name = "o_cached_bean")
|
||||
public class OCachedBean {
|
||||
|
||||
@@ -5,12 +5,12 @@ import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
/**
|
||||
* Cached bean for testing caching implementation, especially relations.
|
||||
*/
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@Entity
|
||||
@Table(name = "o_cached_bean_child")
|
||||
public class OCachedBeanChild {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.DocEmbedded;
|
||||
import com.avaje.ebean.annotation.DocStore;
|
||||
@@ -30,6 +31,7 @@ import java.util.List;
|
||||
/**
|
||||
* Order entity bean.
|
||||
*/
|
||||
@Cache
|
||||
@DocStore
|
||||
@ChangeLog
|
||||
@Entity
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.DocEmbedded;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
@@ -13,146 +14,147 @@ import java.sql.Timestamp;
|
||||
/**
|
||||
* Order Detail entity bean.
|
||||
*/
|
||||
@Cache
|
||||
@Entity
|
||||
@Table(name = "o_order_detail")
|
||||
public class OrderDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
Order order;
|
||||
@ManyToOne(optional = false)
|
||||
Order order;
|
||||
|
||||
Integer orderQty;
|
||||
Integer orderQty;
|
||||
|
||||
Integer shipQty;
|
||||
Integer shipQty;
|
||||
|
||||
Double unitPrice;
|
||||
Double unitPrice;
|
||||
|
||||
@ManyToOne
|
||||
@DocEmbedded(doc = "id,name,sku")
|
||||
Product product;
|
||||
@ManyToOne
|
||||
@DocEmbedded(doc = "id,name,sku")
|
||||
Product product;
|
||||
|
||||
Timestamp cretime;
|
||||
Timestamp cretime;
|
||||
|
||||
@Version
|
||||
Timestamp updtime;
|
||||
@Version
|
||||
Timestamp updtime;
|
||||
|
||||
public OrderDetail() {
|
||||
}
|
||||
public OrderDetail() {
|
||||
}
|
||||
|
||||
public OrderDetail(Product product, Integer orderQty, Double unitPrice) {
|
||||
this.product = product;
|
||||
this.orderQty = orderQty;
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
public OrderDetail(Product product, Integer orderQty, Double unitPrice) {
|
||||
this.product = product;
|
||||
this.orderQty = orderQty;
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return id.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Return id.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set id.
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* Set id.
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order qty.
|
||||
*/
|
||||
public Integer getOrderQty() {
|
||||
return orderQty;
|
||||
}
|
||||
/**
|
||||
* Return order qty.
|
||||
*/
|
||||
public Integer getOrderQty() {
|
||||
return orderQty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order qty.
|
||||
*/
|
||||
public void setOrderQty(Integer orderQty) {
|
||||
this.orderQty = orderQty;
|
||||
}
|
||||
/**
|
||||
* Set order qty.
|
||||
*/
|
||||
public void setOrderQty(Integer orderQty) {
|
||||
this.orderQty = orderQty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ship qty.
|
||||
*/
|
||||
public Integer getShipQty() {
|
||||
return shipQty;
|
||||
}
|
||||
/**
|
||||
* Return ship qty.
|
||||
*/
|
||||
public Integer getShipQty() {
|
||||
return shipQty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ship qty.
|
||||
*/
|
||||
public void setShipQty(Integer shipQty) {
|
||||
this.shipQty = shipQty;
|
||||
}
|
||||
/**
|
||||
* Set ship qty.
|
||||
*/
|
||||
public void setShipQty(Integer shipQty) {
|
||||
this.shipQty = shipQty;
|
||||
}
|
||||
|
||||
public Double getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
public Double getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(Double unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
public void setUnitPrice(Double unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return cretime.
|
||||
*/
|
||||
public Timestamp getCretime() {
|
||||
return cretime;
|
||||
}
|
||||
/**
|
||||
* Return cretime.
|
||||
*/
|
||||
public Timestamp getCretime() {
|
||||
return cretime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cretime.
|
||||
*/
|
||||
public void setCretime(Timestamp cretime) {
|
||||
this.cretime = cretime;
|
||||
}
|
||||
/**
|
||||
* Set cretime.
|
||||
*/
|
||||
public void setCretime(Timestamp cretime) {
|
||||
this.cretime = cretime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return updtime.
|
||||
*/
|
||||
public Timestamp getUpdtime() {
|
||||
return updtime;
|
||||
}
|
||||
/**
|
||||
* Return updtime.
|
||||
*/
|
||||
public Timestamp getUpdtime() {
|
||||
return updtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set updtime.
|
||||
*/
|
||||
public void setUpdtime(Timestamp updtime) {
|
||||
this.updtime = updtime;
|
||||
}
|
||||
/**
|
||||
* Set updtime.
|
||||
*/
|
||||
public void setUpdtime(Timestamp updtime) {
|
||||
this.updtime = updtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order.
|
||||
*/
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
/**
|
||||
* Return order.
|
||||
*/
|
||||
public Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order.
|
||||
*/
|
||||
public void setOrder(Order order) {
|
||||
this.order = order;
|
||||
}
|
||||
/**
|
||||
* Set order.
|
||||
*/
|
||||
public void setOrder(Order order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return product.
|
||||
*/
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
/**
|
||||
* Return product.
|
||||
*/
|
||||
public Product getProduct() {
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set product.
|
||||
*/
|
||||
public void setProduct(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
/**
|
||||
* Set product.
|
||||
*/
|
||||
public void setProduct(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import javax.persistence.Version;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheQueryTuning;
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
import com.avaje.ebean.annotation.DocStore;
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.avaje.ebean.annotation.DocStore;
|
||||
* Product entity bean.
|
||||
*/
|
||||
@DocStore
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@CacheQueryTuning(maxSecsToLive = 15)
|
||||
@Entity
|
||||
@Table(name = "o_product")
|
||||
|
||||
@@ -9,9 +9,9 @@ import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
@CacheStrategy(useBeanCache=true)
|
||||
@Cache
|
||||
@Entity
|
||||
public class Section extends BasicDomain {
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.avaje.tests.model.basic;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
@CacheStrategy(useBeanCache=true)
|
||||
@Cache
|
||||
@Entity
|
||||
public class SubSection extends BasicDomain {
|
||||
|
||||
|
||||
@@ -1,47 +1,49 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Cache
|
||||
@Entity
|
||||
public class UUOne {
|
||||
|
||||
@Id
|
||||
UUID id;
|
||||
|
||||
String name;
|
||||
@Id
|
||||
UUID id;
|
||||
|
||||
String name;
|
||||
|
||||
|
||||
@OneToMany(cascade=CascadeType.ALL, mappedBy="master")
|
||||
List<UUTwo> comments;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "master")
|
||||
List<UUTwo> comments;
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<UUTwo> getComments() {
|
||||
return comments;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<UUTwo> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(List<UUTwo> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public void setComments(List<UUTwo> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.tests.model.basic.cache;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@Entity
|
||||
@Inheritance
|
||||
@DiscriminatorValue("O")
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.avaje.tests.model.basic.cache;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
import com.avaje.tests.model.basic.BasicDomain;
|
||||
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@Entity
|
||||
@Inheritance
|
||||
@DiscriminatorColumn(length = 3)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.tests.model.basic.cache;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
|
||||
@CacheStrategy
|
||||
@Cache
|
||||
@Entity
|
||||
@Inheritance
|
||||
@DiscriminatorValue("T")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.model.embedded;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
@@ -11,6 +13,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Cache
|
||||
@Entity
|
||||
public class EInvoice {
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.tests.model.m2m;
|
||||
|
||||
import com.avaje.ebean.annotation.CacheStrategy;
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@@ -14,7 +14,7 @@ import java.util.UUID;
|
||||
* The Class Permission.
|
||||
*/
|
||||
@Entity
|
||||
@CacheStrategy(readOnly = true)
|
||||
@Cache(readOnly = true)
|
||||
@Table(name = "mt_permission")
|
||||
public class Permission {
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ public class TestMultipleEmbeddedLoading extends BaseTestCase {
|
||||
invoice2.getBillAddress().setStreet("3 Pineapple St");
|
||||
// bean should be dirty
|
||||
Ebean.save(invoice2);
|
||||
|
||||
awaitL2Cache();
|
||||
|
||||
EInvoice invoice3 = Ebean.find(EInvoice.class)
|
||||
.where().idEq(invoice.getId())
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.avaje.tests.transaction;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.tests.model.basic.EBasicVer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TestDeleteFromPersistenceContext extends BaseTestCase {
|
||||
|
||||
@@ -25,30 +27,33 @@ public class TestDeleteFromPersistenceContext extends BaseTestCase {
|
||||
try {
|
||||
|
||||
EBasicVer bean2 = Ebean.find(EBasicVer.class, bean.getId());
|
||||
Assert.assertNotSame(bean, bean2);
|
||||
assertNotSame(bean, bean2);
|
||||
|
||||
EBasicVer bean3 = Ebean.find(EBasicVer.class, bean.getId());
|
||||
// same instance from PersistenceContext
|
||||
Assert.assertSame(bean2, bean3);
|
||||
assertSame(bean2, bean3);
|
||||
|
||||
Object bean4 = transaction.getPersistenceContext().get(EBasicVer.class, bean.getId());
|
||||
Assert.assertSame(bean2, bean4);
|
||||
assertSame(bean2, bean4);
|
||||
|
||||
Ebean.delete(bean2);
|
||||
|
||||
Object bean5 = transaction.getPersistenceContext().get(EBasicVer.class, bean.getId());
|
||||
Assert.assertNull("Bean is deleted from PersistenceContext",bean5);
|
||||
|
||||
EBasicVer bean6 = Ebean.find(EBasicVer.class).where().eq("id", bean.getId()).findUnique();
|
||||
Assert.assertNull("Bean where id eq is not found "+bean6, bean6);
|
||||
|
||||
EBasicVer bean7 = Ebean.find(EBasicVer.class, bean.getId());
|
||||
Assert.assertNull("Bean is not expected to be found? "+bean7, bean7);
|
||||
|
||||
assertNull("Bean is deleted from PersistenceContext",bean5);
|
||||
|
||||
Ebean.commitTransaction();
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
|
||||
|
||||
EBasicVer bean6 = Ebean.find(EBasicVer.class).where().eq("id", bean.getId()).findUnique();
|
||||
assertNull("Bean where id eq is not found "+bean6, bean6);
|
||||
|
||||
awaitL2Cache();
|
||||
EBasicVer bean7 = Ebean.find(EBasicVer.class, bean.getId());
|
||||
assertNull("Bean is not expected to be found? "+bean7, bean7);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user