dain 2004/10/13 14:53:23
Modified: modules/core/src/java/org/openejb/entity/cmp
CMPContainerBuilder.java
CMPInstanceContextFactory.java
Log:
CMP 1.1 beans now deploy... you can't use them but deployment won't complain
Synchronized version-info with geronimo
Revision Changes Path
1.26 +15 -3
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPContainerBuilder.java
Index: CMPContainerBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPContainerBuilder.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- CMPContainerBuilder.java 12 Oct 2004 20:01:13 -0000 1.25
+++ CMPContainerBuilder.java 13 Oct 2004 18:53:23 -0000 1.26
@@ -120,12 +120,21 @@
* @version $Revision$ $Date$
*/
public class CMPContainerBuilder extends AbstractContainerBuilder {
+ private boolean cmp2 = true;
private EJBSchema ejbSchema;
private Schema sqlSchema;
private EJB ejb;
private String connectionFactoryName;
private Map queries;
+ public boolean isCMP2() {
+ return cmp2;
+ }
+
+ public void setCMP2(boolean cmp2) {
+ this.cmp2 = cmp2;
+ }
+
protected int getEJBComponentType() {
return EJBComponentType.CMP_ENTITY;
}
@@ -254,9 +263,12 @@
// build the instance factory
LinkedHashMap cmpFieldAccessors = createCMPFieldAccessors(faultHandler);
- Map instanceMap = buildInstanceMap(beanClass, cmpFieldAccessors);
+ Map instanceMap = null;
+ if (cmp2) {
+ instanceMap = buildInstanceMap(beanClass, cmpFieldAccessors);
+ }
- InstanceContextFactory contextFactory = new
CMPInstanceContextFactory(getContainerId(), primaryKeyTransform, faultHandler,
beanClass, instanceMap, getUnshareableResources(),
getApplicationManagedSecurityResources());
+ InstanceContextFactory contextFactory = new
CMPInstanceContextFactory(getContainerId(), cmp2, primaryKeyTransform, faultHandler,
beanClass, instanceMap, getUnshareableResources(),
getApplicationManagedSecurityResources());
EntityInstanceFactory instanceFactory = new
EntityInstanceFactory(contextFactory);
// build the pool
1.14 +44 -24
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContextFactory.java
Index: CMPInstanceContextFactory.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContextFactory.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CMPInstanceContextFactory.java 5 Oct 2004 07:04:00 -0000 1.13
+++ CMPInstanceContextFactory.java 13 Oct 2004 18:53:23 -0000 1.14
@@ -47,15 +47,16 @@
*/
package org.openejb.entity.cmp;
-import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
+import javax.ejb.EJBException;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
@@ -81,6 +82,7 @@
*/
public class CMPInstanceContextFactory implements InstanceContextFactory,
Serializable {
private final Object containerId;
+ private final boolean cmp2;
private final IdentityTransform primaryKeyTransform;
private final FaultHandler loadFault;
private final Class beanClass;
@@ -89,14 +91,16 @@
private final Set applicationManagedSecurityResources;
private transient final InstanceOperation[] itable;
private transient final Enhancer enhancer;
+ private transient final FastClass beanFastClass;
private transient EJBProxyFactory proxyFactory;
private transient Interceptor systemChain;
private transient SystemMethodIndices systemMethodIndices;
private transient TransactionContextManager transactionContextManager;
private transient BasicTimerService timerService;
- public CMPInstanceContextFactory(Object containerId, IdentityTransform
primaryKeyTransform, FaultHandler loadFault, Class beanClass, Map imap, Set
unshareableResources, Set applicationManagedSecurityResources) {
+ public CMPInstanceContextFactory(Object containerId, boolean cmp2,
IdentityTransform primaryKeyTransform, FaultHandler loadFault, Class beanClass, Map
imap, Set unshareableResources, Set applicationManagedSecurityResources) {
this.containerId = containerId;
+ this.cmp2 = cmp2;
this.primaryKeyTransform = primaryKeyTransform;
this.loadFault = loadFault;
this.beanClass = beanClass;
@@ -104,22 +108,28 @@
this.unshareableResources = unshareableResources;
this.applicationManagedSecurityResources =
applicationManagedSecurityResources;
- // create a factory to generate concrete subclasses of the abstract cmp
implementation class
- enhancer = new Enhancer();
- enhancer.setSuperclass(beanClass);
- enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
- enhancer.setCallbackFilter(FILTER);
- enhancer.setUseFactory(false);
- Class enhancedClass = enhancer.createClass();
-
- FastClass fastClass = FastClass.create(enhancedClass);
-
- itable = new InstanceOperation[fastClass.getMaxIndex() + 1];
- for (Iterator iterator = imap.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- MethodSignature signature = (MethodSignature) entry.getKey();
- InstanceOperation iop = (InstanceOperation) entry.getValue();
- itable[MethodHelper.getSuperIndex(enhancedClass, signature)] = iop;
+ if (cmp2) {
+ // create a factory to generate concrete subclasses of the abstract cmp
implementation class
+ enhancer = new Enhancer();
+ enhancer.setSuperclass(beanClass);
+ enhancer.setCallbackTypes(new Class[]{NoOp.class,
MethodInterceptor.class});
+ enhancer.setCallbackFilter(FILTER);
+ enhancer.setUseFactory(false);
+ Class enhancedClass = enhancer.createClass();
+
+ beanFastClass = FastClass.create(enhancedClass);
+
+ itable = new InstanceOperation[beanFastClass.getMaxIndex() + 1];
+ for (Iterator iterator = imap.entrySet().iterator();
iterator.hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ MethodSignature signature = (MethodSignature) entry.getKey();
+ InstanceOperation iop = (InstanceOperation) entry.getValue();
+ itable[MethodHelper.getSuperIndex(enhancedClass, signature)] = iop;
+ }
+ } else {
+ enhancer = null;
+ itable = null;
+ beanFastClass = FastClass.create(beanClass);
}
}
@@ -151,9 +161,19 @@
return new CMPInstanceContext(containerId, proxyFactory, itable, loadFault,
primaryKeyTransform, this, systemChain, systemMethodIndices, unshareableResources,
applicationManagedSecurityResources, transactionContextManager, timerService);
}
- public synchronized EntityBean createCMPBeanInstance(CMPInstanceContext
instanceContext) {
- enhancer.setCallbacks(new Callback[]{NoOp.INSTANCE, instanceContext});
- return (EntityBean) enhancer.create();
+ public EntityBean createCMPBeanInstance(CMPInstanceContext instanceContext) {
+ if (cmp2) {
+ synchronized (this) {
+ enhancer.setCallbacks(new Callback[]{NoOp.INSTANCE,
instanceContext});
+ return (EntityBean) enhancer.create();
+ }
+ } else {
+ try {
+ return (EntityBean) beanFastClass.newInstance();
+ } catch (InvocationTargetException e) {
+ throw new EJBException("Unable to create entity bean instance", e);
+ }
+ }
}
private static final CallbackFilter FILTER = new CallbackFilter() {
@@ -165,7 +185,7 @@
}
};
- private Object readResolve() throws ObjectStreamException {
- return new CMPInstanceContextFactory(containerId, primaryKeyTransform,
loadFault, beanClass, imap, unshareableResources, applicationManagedSecurityResources);
+ private Object readResolve() {
+ return new CMPInstanceContextFactory(containerId, cmp2,
primaryKeyTransform, loadFault, beanClass, imap, unshareableResources,
applicationManagedSecurityResources);
}
}