mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Embedded beans support in l2 cache - initial work
This commit is contained in:
@@ -2,8 +2,7 @@ package com.avaje.ebeaninternal.server.cache;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
@@ -11,10 +10,13 @@ import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Customer.Status;
|
||||
import com.avaje.tests.model.embedded.EAddress;
|
||||
import com.avaje.tests.model.embedded.EPerson;
|
||||
|
||||
public class TestCacheBeanData extends BaseTestCase {
|
||||
|
||||
@@ -68,4 +70,54 @@ public class TestCacheBeanData extends BaseTestCase {
|
||||
Assert.assertNotNull(newCustomer.getBillingAddress().getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCacheBeanExtractAndLoadWithEmbdedded() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
BeanDescriptor<EPerson> desc = server.getBeanDescriptor(EPerson.class);
|
||||
BeanPropertyAssocOne<?> addressBeanProperty = (BeanPropertyAssocOne<?>)desc.getBeanProperty("address");
|
||||
|
||||
EAddress address = new EAddress();
|
||||
address.setStreet("92 Someplace Else");
|
||||
address.setSuburb("Sandringham");
|
||||
address.setCity("Auckland");
|
||||
|
||||
EPerson person = new EPerson();
|
||||
person.setId(98989L);
|
||||
person.setName("Rob");
|
||||
person.setAddress(address);
|
||||
|
||||
CachedBeanData addressCacheData = (CachedBeanData)addressBeanProperty.getCacheDataValue((EntityBean) person);
|
||||
|
||||
EPerson newPersonCheck = new EPerson();
|
||||
newPersonCheck.setId(98989L);
|
||||
addressBeanProperty.setCacheDataValue((EntityBean) newPersonCheck, addressCacheData);
|
||||
|
||||
EAddress newAddress = newPersonCheck.getAddress();
|
||||
Assert.assertEquals(address.getStreet(), newAddress.getStreet());
|
||||
Assert.assertEquals(address.getCity(), newAddress.getCity());
|
||||
Assert.assertEquals(address.getSuburb(), newAddress.getSuburb());
|
||||
|
||||
|
||||
|
||||
|
||||
CachedBeanData cacheData = desc.cacheBeanExtractData((EntityBean)person);
|
||||
|
||||
Assert.assertNotNull(cacheData);
|
||||
|
||||
EPerson newPerson = new EPerson();
|
||||
desc.cacheBeanLoadData((EntityBean)newPerson, cacheData);
|
||||
|
||||
Assert.assertNotNull(newPerson.getId());
|
||||
Assert.assertNotNull(newPerson.getName());
|
||||
Assert.assertNotNull(newPerson.getAddress());
|
||||
|
||||
Assert.assertEquals(person.getId(), newPerson.getId());
|
||||
Assert.assertEquals(person.getName(), newPerson.getName());
|
||||
Assert.assertEquals(person.getAddress().getStreet(), newPerson.getAddress().getStreet());
|
||||
Assert.assertEquals(person.getAddress().getCity(), newPerson.getAddress().getCity());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.avaje.tests.model.embedded;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class EAddress {
|
||||
|
||||
String street;
|
||||
|
||||
String suburb;
|
||||
|
||||
String city;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getSuburb() {
|
||||
return suburb;
|
||||
}
|
||||
|
||||
public void setSuburb(String suburb) {
|
||||
this.suburb = suburb;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.avaje.tests.model.embedded;
|
||||
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class EPerson {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
String name;
|
||||
|
||||
String notes;
|
||||
|
||||
@Embedded
|
||||
EAddress address;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public EAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(EAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,16 +3,16 @@ package com.avaje.tests.model.embedded;
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class Eembeddable
|
||||
{
|
||||
String description;
|
||||
public class Eembeddable {
|
||||
|
||||
String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user