Merge branch 'master' of https://github.com/SamhammerAG/ebean into SamhammerAG-master

This commit is contained in:
rob bygrave
2017-06-23 19:52:55 +12:00
3 changed files with 131 additions and 0 deletions
@@ -0,0 +1,57 @@
package org.tests.cache;
import org.tests.model.basic.L2CachedLazyDirtFlagResetBean;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class TestL2DirtyFlagOnLazyLoad extends BaseTestCase {
@Test
public void dirtyFlag_reset_after_lazy() {
//PREPARE
Transaction tx0 = Ebean.beginTransaction();
L2CachedLazyDirtFlagResetBean bean = new L2CachedLazyDirtFlagResetBean();
bean.setName("findById");
Ebean.save(bean);
//bean.save();
tx0.commit();
// clearAll() caches via the ServerCacheManager ...
// Clear all the caches on the default/primary EbeanServer
server().getServerCacheManager().clearAll();
//TEST
Transaction tx1 = Ebean.beginTransaction();
// load (and dont touch any related entity)
L2CachedLazyDirtFlagResetBean bean1 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
tx1.commit();
Transaction tx2 = Ebean.beginTransaction();
// load (and modify)
L2CachedLazyDirtFlagResetBean bean2 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
assertNotNull(bean2);
assertEquals("findById", bean2.getName());
bean2.setName("something");
bean2.someRichObjectMethod();
Ebean.update(bean2);
tx2.commit();
Transaction tx3 = Ebean.beginTransaction();
// validation
L2CachedLazyDirtFlagResetBean bean3 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
assertEquals("something", bean3.getName());
tx3.rollback();
}
}
@@ -0,0 +1,51 @@
package org.tests.model.basic;
import io.ebean.annotation.Cache;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
/**
* Cached bean for testing caching implementation.
*/
@Cache
@Entity
@Table(name = "l2_cached_lazy_dirt_flag_reset_bean")
public class L2CachedLazyDirtFlagResetBean {
public Long getId() {
return id;
}
@Id
Long id;
String name;
public List<L2CachedLazyDirtFlagResetBeanChild> getChildren() {
return children;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
List<L2CachedLazyDirtFlagResetBeanChild> children;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Long> someRichObjectMethod() {
List<Long> result = new ArrayList<Long>();
if(this.children != null) {
for (L2CachedLazyDirtFlagResetBeanChild relation : this.children) {
result.add(relation.getId());
}
}
return result;
}
}
@@ -0,0 +1,23 @@
package org.tests.model.basic;
import javax.persistence.*;
@Entity
@Table(name = "l2_cached_lazy_dirt_flag_reset_bean_child")
public class L2CachedLazyDirtFlagResetBeanChild {
@Id
Long id;
@ManyToOne
@Column(nullable = false)
L2CachedLazyDirtFlagResetBean parent;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}