mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove Subclassing/Dynamic Proxy support - beans must be enhanced
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
package com.avaje.ebean.enhance.agent;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestTransformConstruct extends TestCase {
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
Transformer t = new Transformer("", "");
|
||||
Assert.assertNotNull(t);
|
||||
|
||||
t = new Transformer("d", "");
|
||||
Assert.assertNotNull(t);
|
||||
|
||||
t = new Transformer("dd", "");
|
||||
Assert.assertNotNull(t);
|
||||
|
||||
t = new Transformer((String)null, null);
|
||||
Assert.assertNotNull(t);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
import com.avaje.ebean.bean.SerializeControl;
|
||||
import com.avaje.ebean.common.BeanList;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.Order.Status;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
|
||||
public class TestSerialization extends TestCase {
|
||||
|
||||
public void testSerialization() {
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
Customer customer = server.getReference(Customer.class, 1);
|
||||
|
||||
Order o = server.createEntityBean(Order.class);
|
||||
o.setOrderDate(new Date(System.currentTimeMillis()));
|
||||
o.setStatus(Status.NEW);
|
||||
o.setCustomer(customer);
|
||||
|
||||
BeanList<OrderDetail> details = new BeanList<OrderDetail>();
|
||||
o.setDetails(details);
|
||||
|
||||
EntityBean eb = (EntityBean)o;
|
||||
|
||||
Order orderCopy = (Order)eb._ebean_createCopy();
|
||||
|
||||
Assert.assertNotNull(orderCopy.getDetails());
|
||||
Assert.assertNotNull(orderCopy.getCustomer());
|
||||
|
||||
EntityBeanIntercept ebi = eb._ebean_getIntercept();
|
||||
o.setStatus(Status.APPROVED);
|
||||
|
||||
ebi.setReadOnly(true);
|
||||
ebi.setLoaded();
|
||||
|
||||
try {
|
||||
o.setStatus(Status.COMPLETE);
|
||||
Assert.assertTrue("dont get here",false);
|
||||
} catch (IllegalStateException e){
|
||||
Assert.assertTrue("throws exception",true);
|
||||
}
|
||||
|
||||
SerializeControl.setVanilla(true);
|
||||
Assert.assertTrue(SerializeControl.isVanillaBeans());
|
||||
Assert.assertTrue(SerializeControl.isVanillaCollections());
|
||||
|
||||
Order testUsingSubclassing = new Order();
|
||||
if (testUsingSubclassing instanceof EntityBean){
|
||||
System.out.println("Need to run serialisation test with 'subclassing/proxies'");
|
||||
|
||||
} else {
|
||||
System.out.println("Testing serialisation of 'subclassing/proxies'");
|
||||
Object vanillaOrder = serialWriteRead(o, true);
|
||||
Assert.assertFalse("should be an EntityBean", (vanillaOrder instanceof EntityBean));
|
||||
Assert.assertTrue("should be an Order", (vanillaOrder instanceof Order));
|
||||
|
||||
Order vanOrder = (Order)vanillaOrder;
|
||||
Customer vanCustomer = vanOrder.getCustomer();
|
||||
List<OrderDetail> vanDetails = vanOrder.getDetails();
|
||||
|
||||
Assert.assertFalse("should NOT be an EntityBean", (vanCustomer instanceof EntityBean));
|
||||
Assert.assertFalse("should NOT be an BeanList", (vanDetails instanceof BeanList<?>));
|
||||
Assert.assertTrue("should be an ArrayList", (vanDetails instanceof ArrayList<?>));
|
||||
Assert.assertTrue("should be an Customer", (vanCustomer instanceof Customer));
|
||||
}
|
||||
|
||||
SerializeControl.setVanilla(false);
|
||||
|
||||
Object subclassOrder = serialWriteRead(o, false);
|
||||
Assert.assertTrue("should be an Order", (subclassOrder instanceof Order));
|
||||
Assert.assertTrue("should be an EntityBean", (subclassOrder instanceof EntityBean));
|
||||
|
||||
SerializeControl.setVanilla(true);
|
||||
|
||||
File serTestFile = new File("serTest");
|
||||
if (serTestFile.exists()){
|
||||
serTestFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private Object serialWriteRead(Object inputObject, boolean vanilla){
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
File serTestFile = new File("serTest");
|
||||
FileOutputStream fout = new FileOutputStream(serTestFile);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fout);
|
||||
|
||||
oos.writeObject(inputObject);
|
||||
oos.close();
|
||||
|
||||
FileInputStream fin = new FileInputStream(serTestFile);
|
||||
|
||||
ObjectInputStream ois;
|
||||
if (vanilla){
|
||||
ois = new ObjectInputStream(fin);
|
||||
} else {
|
||||
ois = Ebean.getServer(null).createProxyObjectInputStream(fin);
|
||||
}
|
||||
Object readObject = ois.readObject();
|
||||
ois.close();
|
||||
return readObject;
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestTransientInternalFields extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer c = list.get(0);
|
||||
|
||||
Object back = serialWriteRead(c, false);
|
||||
|
||||
if (back instanceof EntityBean){
|
||||
EntityBean entityBean = (EntityBean)back;
|
||||
EntityBeanIntercept ebi = entityBean._ebean_getIntercept();
|
||||
if (ebi == null){
|
||||
ebi = entityBean._ebean_intercept();
|
||||
Assert.assertNotNull(ebi);
|
||||
}
|
||||
}
|
||||
|
||||
File serTestFile = new File("serTransTest");
|
||||
if (serTestFile.exists()){
|
||||
serTestFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private Object serialWriteRead(Object inputObject, boolean vanilla){
|
||||
|
||||
try {
|
||||
|
||||
File serTestFile = new File("serTransTest");
|
||||
FileOutputStream fout = new FileOutputStream(serTestFile);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fout);
|
||||
|
||||
oos.writeObject(inputObject);
|
||||
oos.close();
|
||||
|
||||
FileInputStream fin = new FileInputStream(serTestFile);
|
||||
|
||||
ObjectInputStream ois;
|
||||
if (vanilla){
|
||||
ois = new ObjectInputStream(fin);
|
||||
} else {
|
||||
ois = Ebean.getServer(null).createProxyObjectInputStream(fin);
|
||||
}
|
||||
Object readObject = ois.readObject();
|
||||
ois.close();
|
||||
return readObject;
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
Assert.assertTrue(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.avaje.tests.basic.vanilla;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestVanillaQuery extends TestCase {
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
Order beanEnhancedCheck = new Order();
|
||||
|
||||
if (beanEnhancedCheck instanceof EntityBean){
|
||||
// test only real when not using enhancement
|
||||
System.out.println("Not testing TestVanillaQuery as beans are enhanced");
|
||||
return;
|
||||
}
|
||||
|
||||
// These settings only work when test run standalone (Ebean not booted yet)
|
||||
GlobalProperties.put("ebean.vanillaMode", "true");
|
||||
GlobalProperties.put("ebean.vanillaRefMode", "true");
|
||||
|
||||
// actually only a vanilla class when using subclass generation
|
||||
Class<?> vanillaClass = Order.class;
|
||||
|
||||
// // ONLY Testing this when running test manually/standalone at this stage
|
||||
// Order oref = Ebean.getReference(Order.class, 1);
|
||||
// Class<?> refClass = oref.getClass();
|
||||
// Assert.assertEquals(vanillaClass, refClass);
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list =
|
||||
Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.setVanillaMode(true)
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
|
||||
Order o = list.get(0);
|
||||
|
||||
// actually only a vanilla class when using subclass generation
|
||||
Class<?> returnedClass = o.getClass();
|
||||
Assert.assertEquals(vanillaClass, returnedClass);
|
||||
|
||||
Ebean.refreshMany(o, "details");
|
||||
|
||||
Ebean.refresh(o);
|
||||
|
||||
if (!(o instanceof EntityBean)){
|
||||
// using subclass generation ...
|
||||
list =
|
||||
Ebean.find(Order.class)
|
||||
.setVanillaMode(false)
|
||||
.findList();
|
||||
|
||||
Class<?> entityBeanClass = list.get(0).getClass();
|
||||
|
||||
Assert.assertNotSame(vanillaClass, entityBeanClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,32 @@ import java.util.List;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
import com.avaje.ebean.TxType;
|
||||
import com.avaje.ebean.annotation.Transactional;
|
||||
|
||||
public class DummyDao {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DummyDao.class);
|
||||
|
||||
@Transactional(type = TxType.REQUIRES_NEW)
|
||||
public void doSomething() {
|
||||
|
||||
System.out.println("Hello World");
|
||||
logger.info(" --- in DummyDao.doSomething() with TxType.REQUIRES_NEW");
|
||||
Transaction txn = Ebean.currentTransaction();
|
||||
if (txn == null) {
|
||||
logger.error(" NO TRANSACTION ??");
|
||||
} else {
|
||||
logger.info(" --- txn - "+txn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
// ebean transactional annotation, not spring transactional annotation
|
||||
public void addToObject(Long id, Double anotherNumber, List<Long> ids) throws EntityNotFoundException {
|
||||
// and more code
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import javax.persistence.OptimisticLockException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Transaction;
|
||||
@@ -14,30 +16,35 @@ import com.avaje.tests.model.basic.xtra.OptimisticLockExceptionThrowingDao;
|
||||
|
||||
public class TestTxTypeOnTransactional extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
DummyDao dao = new DummyDao();
|
||||
dao.doSomething();
|
||||
Logger logger = LoggerFactory.getLogger(TestTxTypeOnTransactional.class);
|
||||
|
||||
public void test() {
|
||||
|
||||
logger.info("-- test pre dao.doSomething");
|
||||
DummyDao dao = new DummyDao();
|
||||
dao.doSomething();
|
||||
logger.info("-- test post dao.doSomething");
|
||||
}
|
||||
|
||||
public void testOptimisticException() {
|
||||
|
||||
logger.info("-- testOptimisticException");
|
||||
EBasicVer v = new EBasicVer();
|
||||
v.setName("occ");
|
||||
v.setDescription("blah");
|
||||
Ebean.save(v);
|
||||
|
||||
logger.info("-- OptimisticLockExceptionThrowingDao");
|
||||
OptimisticLockExceptionThrowingDao dao = new OptimisticLockExceptionThrowingDao();
|
||||
try {
|
||||
dao.doSomething(v);
|
||||
// never get here
|
||||
Assert.assertTrue(false);
|
||||
} catch (OptimisticLockException e) {
|
||||
Transaction inMethodTransaction = dao.getInMethodTransaction();
|
||||
boolean active = inMethodTransaction.isActive();
|
||||
Assert.assertFalse(active);
|
||||
}
|
||||
|
||||
public void testOptimisticException() {
|
||||
|
||||
EBasicVer v = new EBasicVer();
|
||||
v.setName("occ");
|
||||
v.setDescription("blah");
|
||||
Ebean.save(v);
|
||||
|
||||
|
||||
OptimisticLockExceptionThrowingDao dao = new OptimisticLockExceptionThrowingDao();
|
||||
try {
|
||||
dao.doSomething(v);
|
||||
// never get here
|
||||
Assert.assertTrue(false);
|
||||
} catch (OptimisticLockException e){
|
||||
Transaction inMethodTransaction = dao.getInMethodTransaction();
|
||||
boolean active = inMethodTransaction.isActive();
|
||||
Assert.assertFalse(active);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ public class TestStatelessUpdate extends TestCase {
|
||||
server.save(e);
|
||||
|
||||
|
||||
EBasic updateName = new EBasic();
|
||||
updateName.setId(e.getId());
|
||||
updateName.setName("justName");
|
||||
|
||||
|
||||
server.update(updateName, null, null, false, false);
|
||||
// EBasic updateName = new EBasic();
|
||||
// updateName.setId(e.getId());
|
||||
// updateName.setName("justName");
|
||||
//
|
||||
//
|
||||
// server.update(updateName, null, null, false, false);
|
||||
|
||||
EBasic updateAll = new EBasic();
|
||||
updateAll.setId(e.getId());
|
||||
|
||||
@@ -9,7 +9,7 @@ public interface XoiNode {
|
||||
|
||||
public String getNodeName();
|
||||
|
||||
public Object createBean(boolean vanillaMode);
|
||||
public Object createBean();
|
||||
|
||||
public void writeNode(XrOutputDocument out, Node node, Object bean) throws IOException;
|
||||
|
||||
|
||||
@@ -59,14 +59,14 @@ public class XrCollection extends XrNode implements XoiNode {
|
||||
Object parentBean = ctx.getBean();
|
||||
|
||||
// create a List/Set/Map to hold the details
|
||||
Object details = manyProp.createEmpty(ctx.isVanillaMode());
|
||||
Object details = manyProp.createEmpty(false);
|
||||
|
||||
// Wrapper used to add to the collection
|
||||
BeanCollectionAdd bcAdd = manyProp.getBeanCollectionAdd(details, mapKey);
|
||||
|
||||
Node detailNode = nextElement(node.getFirstChild());
|
||||
do {
|
||||
Object detailBean = targetDescriptor.createBean(ctx.isVanillaMode());
|
||||
Object detailBean = targetDescriptor.createBean();
|
||||
ctx.setBean(detailBean);
|
||||
|
||||
for (int i = 0; i < childNodes.length; i++) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class XrContext implements OxmContext {
|
||||
|
||||
XoiNode xoiNode = getXoiNode(node.getNodeName());
|
||||
|
||||
Object bean = xoiNode.createBean(false);
|
||||
Object bean = xoiNode.createBean();
|
||||
|
||||
XrReadContext ctx = new XrReadContext(bean);
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ public class XrNode extends XrBase implements XoiNode {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public Object createBean(boolean vanillaMode) {
|
||||
return beanDescriptor.createBean(vanillaMode);
|
||||
public Object createBean() {
|
||||
return beanDescriptor.createBean();
|
||||
}
|
||||
|
||||
public String getNodeName() {
|
||||
@@ -74,7 +74,7 @@ public class XrNode extends XrBase implements XoiNode {
|
||||
Object parentBean = null;
|
||||
if (assocBeanValue){
|
||||
parentBean = ctx.getBean();
|
||||
Object childBean = beanDescriptor.createBean(ctx.isVanillaMode());
|
||||
Object childBean = beanDescriptor.createBean();
|
||||
setObjectValue(parentBean, childBean);
|
||||
|
||||
ctx.setBean(childBean);
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.avaje.tests.xml.runtime;
|
||||
|
||||
public class XrReadContext {
|
||||
|
||||
private boolean vanillaMode;
|
||||
|
||||
private Object bean;
|
||||
|
||||
public XrReadContext(Object bean) {
|
||||
@@ -17,13 +15,4 @@ public class XrReadContext {
|
||||
public void setBean(Object bean) {
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
public boolean isVanillaMode() {
|
||||
return vanillaMode;
|
||||
}
|
||||
|
||||
public void setVanillaMode(boolean vanillaMode) {
|
||||
this.vanillaMode = vanillaMode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user