dain        2005/02/16 01:12:38

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

  Added reentrancy detection, and throw exception when reentering a 
non-reentrant entity
  
  Revision  Changes    Path
  1.12      +16 -1     
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EntityInstanceContext.java        15 Feb 2005 03:24:02 -0000      1.11
  +++ EntityInstanceContext.java        16 Feb 2005 06:12:38 -0000      1.12
  @@ -76,6 +76,7 @@
       private final EJBInvocation loadInvocation;
       private final EJBInvocation storeInvocation;
       private boolean stateValid;
  +    private int callDepth;
   
       public EntityInstanceContext(Object containerId, EJBProxyFactory 
proxyFactory, EnterpriseBean instance, Interceptor lifecycleInterceptorChain, 
SystemMethodIndices systemMethodIndices, Set unshareableResources, Set 
applicationManagedSecurityResources, TransactionContextManager 
transactionContextManager, BasicTimerService timerService) {
           super(lifecycleInterceptorChain, unshareableResources, 
applicationManagedSecurityResources, instance, proxyFactory, timerService);
  @@ -124,6 +125,20 @@
   
       public void setStateValid(boolean stateValid) {
           this.stateValid = stateValid;
  +    }
  +
  +
  +    public boolean isInCall() {
  +        return callDepth > 0;
  +    }
  +
  +    public void enter() {
  +        callDepth++;
  +    }
  +
  +    public void exit() {
  +        assert isInCall();
  +        callDepth--;
       }
   
       public void ejbActivate() throws Throwable {
  
  
  
  1.12      +15 -2     
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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EntityInstanceInterceptor.java    12 Feb 2005 18:44:00 -0000      1.11
  +++ EntityInstanceInterceptor.java    16 Feb 2005 06:12:38 -0000      1.12
  @@ -57,6 +57,8 @@
   import org.apache.geronimo.transaction.InstanceContext;
   import org.apache.geronimo.transaction.context.TransactionContext;
   import org.openejb.EJBInvocation;
  +import org.openejb.NotReentrantException;
  +import org.openejb.NotReentrantLocalException;
   import org.openejb.cache.InstancePool;
   
   /**
  @@ -69,11 +71,13 @@
       private final Interceptor next;
       private final Object containerId;
       private final InstancePool pool;
  +    private final boolean reentrant;
   
  -    public EntityInstanceInterceptor(Interceptor next, Object containerId, 
InstancePool pool) {
  +    public EntityInstanceInterceptor(Interceptor next, Object containerId, 
InstancePool pool, boolean reentrant) {
           this.next = next;
           this.containerId = containerId;
           this.pool = pool;
  +        this.reentrant = reentrant;
       }
   
       public InvocationResult invoke(final Invocation invocation) throws 
Throwable {
  @@ -119,7 +123,15 @@
           }
   
           ejbInvocation.setEJBInstanceContext(context);
  +        if (!reentrant && context.isInCall()) {
  +            if (ejbInvocation.getType().isLocal()) {
  +                throw new NotReentrantLocalException("" + containerId);
  +            } else {
  +                throw new NotReentrantException("" + containerId);
  +            }
  +        }
           InstanceContext oldContext = 
transactionContext.beginInvocation(context);
  +        context.enter();
           boolean threwException = false;
           try {
               InvocationResult result = next.invoke(invocation);
  @@ -128,6 +140,7 @@
               threwException = true;
               throw t;
           } finally {
  +            context.exit();
               transactionContext.endInvocation(oldContext);
               ejbInvocation.setEJBInstanceContext(null);
   
  
  
  

Reply via email to