djencks     2004/07/07 18:17:33

  Modified:    modules/core/src/java/org/openejb/entity
                        EntityInstanceContext.java
                        EntityInstanceFactory.java
                        EntityInstanceInterceptor.java
                        EntityInterceptorBuilder.java
  Log:

  A lot more work to route system lifecycle calls through a partial interceptor stack 
(OPENEJB-5).  All that is left is ejbCreate methods when called by the container (slsb 
and mdb)
  
  Revision  Changes    Path
  1.5       +10 -13    
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceContext.java
  
  Index: EntityInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EntityInstanceContext.java        31 May 2004 23:48:23 -0000      1.4
  +++ EntityInstanceContext.java        7 Jul 2004 22:17:33 -0000       1.5
  @@ -55,10 +55,9 @@
   import org.apache.geronimo.core.service.Interceptor;
   import org.apache.geronimo.transaction.TransactionContext;
   import org.openejb.AbstractInstanceContext;
  -import org.openejb.EJBInterfaceType;
   import org.openejb.EJBInvocation;
  -import org.openejb.EJBInvocationImpl;
   import org.openejb.EJBOperation;
  +import org.openejb.dispatch.SystemMethodIndices;
   import org.openejb.proxy.EJBProxyFactory;
   
   /**
  @@ -69,21 +68,19 @@
   public abstract class EntityInstanceContext extends AbstractInstanceContext {
       private final Object containerId;
       private final EntityContextImpl entityContext;
  -    private final Interceptor lifecycleInterceptorChain;
       private Object id;
       private final EJBInvocation loadInvocation;
       private final EJBInvocation storeInvocation;
       private boolean stateValid;
   
  -    public EntityInstanceContext(Object containerId, EJBProxyFactory proxyFactory, 
EnterpriseBean instance, Interceptor lifecycleInterceptorChain, int loadIndex, int 
storeIndex, Set unshareableResources, Set applicationManagedSecurityResources) {
  -        super(unshareableResources, applicationManagedSecurityResources, instance, 
proxyFactory);
  +    public EntityInstanceContext(Object containerId, EJBProxyFactory proxyFactory, 
EnterpriseBean instance, Interceptor lifecycleInterceptorChain, SystemMethodIndices 
systemMethodIndices, Set unshareableResources, Set 
applicationManagedSecurityResources) {
  +        super(systemMethodIndices, lifecycleInterceptorChain, unshareableResources, 
applicationManagedSecurityResources, instance, proxyFactory);
           this.containerId = containerId;
  -        this.lifecycleInterceptorChain = lifecycleInterceptorChain;
           entityContext = new EntityContextImpl(this);
  -        loadInvocation = new EJBInvocationImpl(EJBInterfaceType.LIFECYCLE, id, 
loadIndex, null);
  -        loadInvocation.setEJBInstanceContext(this);
  -        storeInvocation = new EJBInvocationImpl(EJBInterfaceType.LIFECYCLE, id, 
storeIndex, null);
  -        storeInvocation.setEJBInstanceContext(this);
  +        loadInvocation = systemMethodIndices.getEjbLoadInvocation(this);
  +        storeInvocation = systemMethodIndices.getEjbStoreInvocation(this);
  +        setContextInvocation = systemMethodIndices.getSetContextInvocation(this, 
entityContext);
  +        unsetContextInvocation = 
systemMethodIndices.getUnsetContextInvocation(this);
       }
   
       public Object getContainerId() {
  @@ -121,7 +118,7 @@
   
       public void associate() throws Throwable {
           if (id != null && !stateValid) {
  -            lifecycleInterceptorChain.invoke(loadInvocation);
  +            systemChain.invoke(loadInvocation);
               stateValid = true;
           }
       }
  @@ -132,7 +129,7 @@
       public void flush() throws Throwable {
           if (id != null) {
               assert (stateValid) : "Trying to invoke ejbStore for invalid instance";
  -            lifecycleInterceptorChain.invoke(storeInvocation);
  +            systemChain.invoke(storeInvocation);
           }
       }
   
  
  
  
  1.4       +13 -30    
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceFactory.java
  
  Index: EntityInstanceFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EntityInstanceFactory.java        4 Apr 2004 01:49:10 -0000       1.3
  +++ EntityInstanceFactory.java        7 Jul 2004 22:17:33 -0000       1.4
  @@ -48,15 +48,13 @@
   package org.openejb.entity;
   
   import java.io.Serializable;
  -import javax.ejb.EntityBean;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.openejb.EJBOperation;
  -import org.openejb.InstanceContextFactory;
  -import org.openejb.cache.InstanceFactory;
   import org.apache.geronimo.naming.java.ReadOnlyContext;
   import org.apache.geronimo.naming.java.RootContext;
  +import org.openejb.InstanceContextFactory;
  +import org.openejb.cache.InstanceFactory;
   
   
   /**
  @@ -69,12 +67,9 @@
    */
   public class EntityInstanceFactory implements InstanceFactory, Serializable {
       private static final Log log = LogFactory.getLog(EntityInstanceFactory.class);
  -
  -    private final ReadOnlyContext componentContext;
       private final InstanceContextFactory factory;
   
  -    public EntityInstanceFactory(ReadOnlyContext componentContext, 
InstanceContextFactory factory) {
  -        this.componentContext = componentContext;
  +    public EntityInstanceFactory(InstanceContextFactory factory) {
           this.factory = factory;
       }
   
  @@ -87,17 +82,16 @@
   
               // create an EJBInstanceContext wrapping the raw instance
               EntityInstanceContext ctx = (EntityInstanceContext) 
factory.newInstance();
  -            EntityBean instance = (EntityBean) ctx.getInstance();
  -
  -            // Activate this components JNDI Component Context
  -            RootContext.setComponentContext(componentContext);
   
  -            // initialize the instance
  -            ctx.setOperation(EJBOperation.SETCONTEXT);
               try {
  -                instance.setEntityContext(ctx.getEntityContext());
  -            } finally {
  -                ctx.setOperation(EJBOperation.INACTIVE);
  +                ctx.setContext();
  +            } catch (Throwable t) {
  +                //TODO check this error handling
  +                if (t instanceof Exception) {
  +                    throw (Exception) t;
  +                } else {
  +                    throw (Error) t;
  +                }
               }
   
               return ctx;
  @@ -108,21 +102,10 @@
   
       public void destroyInstance(Object instance) {
           EntityInstanceContext ctx = (EntityInstanceContext) instance;
  -        EntityBean beanInstance = (EntityBean) ctx.getInstance();
  -
  -        ctx.setOperation(EJBOperation.SETCONTEXT);
  -
  -        // Activate this components JNDI Component Context
  -        ReadOnlyContext oldContext = RootContext.getComponentContext();
  -        RootContext.setComponentContext(componentContext);
           try {
  -            beanInstance.unsetEntityContext();
  +            ctx.unsetContext();
           } catch (Throwable t) {
  -            // We're destroying this instance, so just log and continue
               log.warn("Unexpected error destroying Entity instance", t);
  -        } finally {
  -            ctx.setOperation(EJBOperation.INACTIVE);
  -            RootContext.setComponentContext(oldContext);
           }
       }
   }
  
  
  
  1.7       +11 -9     
openejb/modules/core/src/java/org/openejb/entity/EntityInstanceInterceptor.java
  
  Index: EntityInstanceInterceptor.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInstanceInterceptor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EntityInstanceInterceptor.java    31 May 2004 23:48:23 -0000      1.6
  +++ EntityInstanceInterceptor.java    7 Jul 2004 22:17:33 -0000       1.7
  @@ -90,14 +90,15 @@
               // always activate on the way in....
               context.setId(id);
               try {
  -                context.setOperation(EJBOperation.EJBACTIVATE);
  -                instance.ejbActivate();
  +                context.ejbActivate();
  +//                context.setOperation(EJBOperation.EJBACTIVATE);
  +//                instance.ejbActivate();
               } catch (Throwable t) {
                   // problem activating instance - discard it and throw the problem 
(will cause rollback)
                   pool.remove(context);
                   throw t;
  -            } finally {
  -                context.setOperation(EJBOperation.INACTIVE);
  +//            } finally {
  +//                context.setOperation(EJBOperation.INACTIVE);
               }
   
               // associate this instance with the TransactionContext
  @@ -130,17 +131,18 @@
               if (id != null) {
                   // always passivate on the way out...
                   try {
  -                    context.setOperation(EJBOperation.EJBLOAD);
  +//                    context.setOperation(EJBOperation.EJBLOAD);
                       context.flush();
  -                    context.setOperation(EJBOperation.EJBACTIVATE);
  -                    instance.ejbPassivate();
  +                    context.ejbPassivate();
  +//                    context.setOperation(EJBOperation.EJBACTIVATE);
  +//                    instance.ejbPassivate();
                   } catch (Throwable t) {
                       // problem passivating instance - discard it and throw the 
problem (will cause rollback)
                       pool.remove(context);
                       // throw this exception only if we are not already throwing a 
business exception
                       if (!threwException) throw t;
                   } finally {
  -                    context.setOperation(EJBOperation.INACTIVE);
  +//                    context.setOperation(EJBOperation.INACTIVE);
                       context.setTransactionContext(null);
                       transactionContext.unassociate(context.getContainerId(), id);
                   }
  
  
  
  1.6       +5 -11     
openejb/modules/core/src/java/org/openejb/entity/EntityInterceptorBuilder.java
  
  Index: EntityInterceptorBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityInterceptorBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EntityInterceptorBuilder.java     25 Jun 2004 21:35:12 -0000      1.5
  +++ EntityInterceptorBuilder.java     7 Jul 2004 22:17:33 -0000       1.6
  @@ -53,6 +53,7 @@
   import org.openejb.AbstractInterceptorBuilder;
   import org.openejb.ConnectionTrackingInterceptor;
   import org.openejb.SystemExceptionInterceptor;
  +import org.openejb.TwoChains;
   import org.openejb.dispatch.DispatchInterceptor;
   import org.openejb.security.EJBIdentityInterceptor;
   import org.openejb.security.EJBRunAsInterceptor;
  @@ -66,9 +67,8 @@
    * @version $Revision$ $Date$
    */
   public class EntityInterceptorBuilder extends AbstractInterceptorBuilder {
  -    private Interceptor lifecycleInteceptorChain = null;
   
  -    public Interceptor buildInterceptorChain() {
  +    public TwoChains buildInterceptorChains() {
           if (transactionManager == null) {
               throw new IllegalStateException("Transaction manager must be set before 
building the interceptor chain");
           }
  @@ -85,7 +85,7 @@
           if (trackedConnectionAssociator != null) {
               firstInterceptor = new ConnectionTrackingInterceptor(firstInterceptor, 
trackedConnectionAssociator);
           }
  -        lifecycleInteceptorChain = firstInterceptor;
  +        Interceptor systemChain = firstInterceptor;
           if (securityEnabled) {
               firstInterceptor = new EJBSecurityInterceptor(firstInterceptor, 
containerId, permissionManager);
           }
  @@ -98,13 +98,7 @@
           firstInterceptor = new EntityInstanceInterceptor(firstInterceptor, 
instancePool);
           firstInterceptor = new TransactionContextInterceptor(firstInterceptor, 
transactionManager, transactionPolicyManager);
           firstInterceptor = new SystemExceptionInterceptor(firstInterceptor, 
ejbName);
  -        return firstInterceptor;
  +        return new TwoChains(firstInterceptor, systemChain);
       }
   
  -    public Interceptor getLifecycleInterceptorChain() {
  -        if (lifecycleInteceptorChain == null) {
  -            throw new IllegalStateException("You must call buildInterceptorStack 
once before calling getLifecycleInterceptorChain");
  -        }
  -        return lifecycleInteceptorChain;
  -    }
   }
  
  
  

Reply via email to