dain        2004/10/14 03:07:16

  Modified:    modules/core/src/java/org/openejb/entity/cmp
                        CMPContainerBuilder.java CMPCreateMethod.java
                        CMPInstanceContext.java
                        CMPInstanceContextFactory.java
  Log:

  CMP 1.1 beans now work as well a CMP 2.0 beans
  
  Revision  Changes    Path
  1.27      +16 -12    
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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- CMPContainerBuilder.java  13 Oct 2004 18:53:23 -0000      1.26
  +++ CMPContainerBuilder.java  14 Oct 2004 07:07:16 -0000      1.27
  @@ -253,22 +253,25 @@
                   new InterfaceMethodSignature("findByPrimaryKey", new 
String[]{getPrimaryKeyClassName()}, true),
                   new QueryCommand[]{localProxyLoad, remoteProxyLoad});
   
  -        // build the vop table
  -        LinkedHashMap vopMap = buildVopMap(beanClass, cacheTable, identityDefiner, 
primaryKeyTransform, localProxyTransform, remoteProxyTransform, queryCommands);
  -        InterfaceMethodSignature[] signatures = (InterfaceMethodSignature[]) 
vopMap.keySet().toArray(new InterfaceMethodSignature[vopMap.size()]);
  -        VirtualOperation[] vtable = (VirtualOperation[]) 
vopMap.values().toArray(new VirtualOperation[vopMap.size()]);
  -
  -        // create and intitalize the interceptor moduleBuilder
  -        InterceptorBuilder interceptorBuilder = initializeInterceptorBuilder(new 
EntityInterceptorBuilder(), signatures, vtable);
  -
           // build the instance factory
           LinkedHashMap cmpFieldAccessors = createCMPFieldAccessors(faultHandler);
           Map instanceMap = null;
  +        CMP1Bridge cmp1Bridge = null;
           if (cmp2) {
               instanceMap = buildInstanceMap(beanClass, cmpFieldAccessors);
  +        } else {
  +            cmp1Bridge = new CMP1Bridge(beanClass, cmpFieldAccessors);
           }
   
  -        InstanceContextFactory contextFactory = new 
CMPInstanceContextFactory(getContainerId(), cmp2, primaryKeyTransform, faultHandler, 
beanClass, instanceMap, getUnshareableResources(), 
getApplicationManagedSecurityResources());
  +        // build the vop table
  +        LinkedHashMap vopMap = buildVopMap(beanClass, cacheTable, cmp1Bridge, 
identityDefiner, primaryKeyTransform, localProxyTransform, remoteProxyTransform, 
queryCommands);
  +        InterfaceMethodSignature[] signatures = (InterfaceMethodSignature[]) 
vopMap.keySet().toArray(new InterfaceMethodSignature[vopMap.size()]);
  +        VirtualOperation[] vtable = (VirtualOperation[]) 
vopMap.values().toArray(new VirtualOperation[vopMap.size()]);
  +
  +        // create and intitalize the interceptor moduleBuilder
  +        InterceptorBuilder interceptorBuilder = initializeInterceptorBuilder(new 
EntityInterceptorBuilder(), signatures, vtable);
  +
  +        InstanceContextFactory contextFactory = new 
CMPInstanceContextFactory(getContainerId(), cmp1Bridge, primaryKeyTransform, 
faultHandler, beanClass, instanceMap, getUnshareableResources(), 
getApplicationManagedSecurityResources());
           EntityInstanceFactory instanceFactory = new 
EntityInstanceFactory(contextFactory);
   
           // build the pool
  @@ -397,9 +400,9 @@
           }
       }
   
  -    protected LinkedHashMap buildVopMap(
  -            Class beanClass,
  +    protected LinkedHashMap buildVopMap(Class beanClass,
               CacheTable cacheTable,
  +            CMP1Bridge cmp1Bridge,
               IdentityDefiner identityDefiner,
               IdentityTransform primaryKeyTransform,
               IdentityTransform localProxyTransform,
  @@ -452,6 +455,7 @@
                           MethodHelper.translateToInterface(signature),
                           new CMPCreateMethod(
                                   beanClass,
  +                                cmp1Bridge,
                                   signature,
                                   postCreateSignature,
                                   cacheTable,
  
  
  
  1.7       +10 -4     
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java
  
  Index: CMPCreateMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPCreateMethod.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CMPCreateMethod.java      18 Jul 2004 22:32:22 -0000      1.6
  +++ CMPCreateMethod.java      14 Oct 2004 07:07:16 -0000      1.7
  @@ -75,6 +75,7 @@
    */
   public class CMPCreateMethod implements VirtualOperation, Serializable {
       private final Class beanClass;
  +    private final CMP1Bridge cmp1Bridge;
       private final MethodSignature createSignature;
       private final MethodSignature postCreateSignature;
       private final CacheTable cacheTable;
  @@ -86,8 +87,8 @@
       private final transient int createIndex;
       private final transient int postCreateIndex;
   
  -    public CMPCreateMethod(
  -            Class beanClass,
  +    public CMPCreateMethod(Class beanClass,
  +            CMP1Bridge cmp1Bridge,
               MethodSignature createSignature,
               MethodSignature postCreateSignature,
               CacheTable cacheTable,
  @@ -96,6 +97,7 @@
               IdentityTransform remoteProxyTransform) {
   
           this.beanClass = beanClass;
  +        this.cmp1Bridge = cmp1Bridge;
           this.createSignature = createSignature;
           this.postCreateSignature = postCreateSignature;
           this.cacheTable = cacheTable;
  @@ -145,6 +147,10 @@
               ctx.setOperation(EJBOperation.INACTIVE);
           }
   
  +        if (cmp1Bridge != null) {
  +            cmp1Bridge.loadCacheRow(ctx, cacheRow);
  +        }
  +
           // define identity (may require insert to database)
           GlobalIdentity globalId = identityDefiner.defineIdentity(cacheRow);
   
  @@ -188,6 +194,6 @@
       }
   
       private Object readResolve() {
  -        return new CMPCreateMethod(beanClass, createSignature, postCreateSignature, 
cacheTable, identityDefiner, localProxyTransform, remoteProxyTransform);
  +        return new CMPCreateMethod(beanClass, cmp1Bridge, createSignature, 
postCreateSignature, cacheTable, identityDefiner, localProxyTransform, 
remoteProxyTransform);
       }
   }
  
  
  
  1.14      +11 -2     
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContext.java
  
  Index: CMPInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPInstanceContext.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CMPInstanceContext.java   5 Oct 2004 07:04:00 -0000       1.13
  +++ CMPInstanceContext.java   14 Oct 2004 07:07:16 -0000      1.14
  @@ -74,14 +74,16 @@
    * @version $Revision$ $Date$
    */
   public final class CMPInstanceContext extends EntityInstanceContext implements 
MethodInterceptor {
  +    private final CMP1Bridge cmp1Bridge;
       private final InstanceOperation[] itable;
       private final FaultHandler loadFault;
       private final IdentityTransform primaryKeyTransform;
       private CacheRow cacheRow;
       private TransactionContext transactionContext;
   
  -    public CMPInstanceContext(Object containerId, EJBProxyFactory proxyFactory, 
InstanceOperation[] itable, FaultHandler loadFault, IdentityTransform 
primaryKeyTransform, CMPInstanceContextFactory contextFactory, Interceptor 
lifecycleInterceptorChain, SystemMethodIndices systemMethodIndices, Set 
unshareableResources, Set applicationManagedSecurityResources, 
TransactionContextManager transactionContextManager, BasicTimerService timerService) 
throws Exception {
  +    public CMPInstanceContext(Object containerId, EJBProxyFactory proxyFactory, 
CMP1Bridge cmp1Bridge, InstanceOperation[] itable, FaultHandler loadFault, 
IdentityTransform primaryKeyTransform, CMPInstanceContextFactory contextFactory, 
Interceptor lifecycleInterceptorChain, SystemMethodIndices systemMethodIndices, Set 
unshareableResources, Set applicationManagedSecurityResources, 
TransactionContextManager transactionContextManager, BasicTimerService timerService) 
throws Exception {
           super(containerId, proxyFactory, null, lifecycleInterceptorChain, 
systemMethodIndices, unshareableResources, applicationManagedSecurityResources, 
transactionContextManager, timerService);
  +        this.cmp1Bridge = cmp1Bridge;
           this.itable = itable;
           this.loadFault = loadFault;
           this.primaryKeyTransform = primaryKeyTransform;
  @@ -136,13 +138,20 @@
               }
   
               // copy data from tranql into instance
  +            if (cmp1Bridge != null) {
  +                cmp1Bridge.loadEntityBean(cacheRow, this);
  +            }
           }
           super.associate();
       }
   
       public void flush() throws Throwable {
           super.flush();
  +
           // copy data from instance into tranql
  +        if (cmp1Bridge != null && cacheRow != null) {
  +            cmp1Bridge.loadCacheRow(this, cacheRow);
  +        }
       }
   
       public void afterCommit(boolean status) {
  
  
  
  1.15      +8 -8      
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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CMPInstanceContextFactory.java    13 Oct 2004 18:53:23 -0000      1.14
  +++ CMPInstanceContextFactory.java    14 Oct 2004 07:07:16 -0000      1.15
  @@ -82,7 +82,7 @@
    */
   public class CMPInstanceContextFactory implements InstanceContextFactory, 
Serializable {
       private final Object containerId;
  -    private final boolean cmp2;
  +    private final CMP1Bridge cmp1Bridge;
       private final IdentityTransform primaryKeyTransform;
       private final FaultHandler loadFault;
       private final Class beanClass;
  @@ -98,9 +98,9 @@
       private transient TransactionContextManager transactionContextManager;
       private transient BasicTimerService timerService;
   
  -    public CMPInstanceContextFactory(Object containerId, boolean cmp2, 
IdentityTransform primaryKeyTransform, FaultHandler loadFault, Class beanClass, Map 
imap, Set unshareableResources, Set applicationManagedSecurityResources) {
  +    public CMPInstanceContextFactory(Object containerId, CMP1Bridge cmp1Bridge, 
IdentityTransform primaryKeyTransform, FaultHandler loadFault, Class beanClass, Map 
imap, Set unshareableResources, Set applicationManagedSecurityResources) {
           this.containerId = containerId;
  -        this.cmp2 = cmp2;
  +        this.cmp1Bridge = cmp1Bridge;
           this.primaryKeyTransform = primaryKeyTransform;
           this.loadFault = loadFault;
           this.beanClass = beanClass;
  @@ -108,7 +108,7 @@
           this.unshareableResources = unshareableResources;
           this.applicationManagedSecurityResources = 
applicationManagedSecurityResources;
   
  -        if (cmp2) {
  +        if (cmp1Bridge == null) {
               // create a factory to generate concrete subclasses of the abstract cmp 
implementation class
               enhancer = new Enhancer();
               enhancer.setSuperclass(beanClass);
  @@ -158,11 +158,11 @@
           if (proxyFactory == null) {
               throw new IllegalStateException("ProxyFactory has not been set");
           }
  -        return new CMPInstanceContext(containerId, proxyFactory, itable, loadFault, 
primaryKeyTransform, this, systemChain, systemMethodIndices, unshareableResources, 
applicationManagedSecurityResources, transactionContextManager, timerService);
  +        return new CMPInstanceContext(containerId, proxyFactory, cmp1Bridge, 
itable, loadFault, primaryKeyTransform, this, systemChain, systemMethodIndices, 
unshareableResources, applicationManagedSecurityResources, transactionContextManager, 
timerService);
       }
   
       public EntityBean createCMPBeanInstance(CMPInstanceContext instanceContext) {
  -        if (cmp2) {
  +        if (cmp1Bridge == null) {
               synchronized (this) {
                   enhancer.setCallbacks(new Callback[]{NoOp.INSTANCE, 
instanceContext});
                   return (EntityBean) enhancer.create();
  @@ -186,6 +186,6 @@
       };
   
       private Object readResolve() {
  -        return new CMPInstanceContextFactory(containerId, cmp2, 
primaryKeyTransform, loadFault, beanClass, imap, unshareableResources, 
applicationManagedSecurityResources);
  +        return new CMPInstanceContextFactory(containerId, cmp1Bridge, 
primaryKeyTransform, loadFault, beanClass, imap, unshareableResources, 
applicationManagedSecurityResources);
       }
   }
  
  
  

Reply via email to