dain        2005/02/25 18:06:09

  Modified:    modules/core/src/java/org/openejb
                        AbstractInstanceContext.java
                        EJBInstanceContext.java
  Log:

  Added support for in-tx cacheing back in
  This unturned a load of places that were not handling transaction contexts 
properly and bugs in the context itself
  Changed instance contexts so they track entrancy and can be killed as 
required by the spec
  Made all instance context fields final
  
  Revision  Changes    Path
  1.10      +56 -29    
openejb/modules/core/src/java/org/openejb/AbstractInstanceContext.java
  
  Index: AbstractInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/AbstractInstanceContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractInstanceContext.java      16 Feb 2005 06:12:38 -0000      1.9
  +++ AbstractInstanceContext.java      25 Feb 2005 23:06:09 -0000      1.10
  @@ -37,55 +37,65 @@
    *
    * */
   public abstract class AbstractInstanceContext implements EJBInstanceContext {
  -
  -    private final Map connectionManagerMap = new HashMap();
  -    private final Set unshareableResources;
  -    private final Set applicationManagedSecurityResources;
  -
  -    //this not being final sucks, but the CMP instance is not available 
until after the superclass constructor executes.
  -    protected EnterpriseBean instance;
  -
  -    private final EJBProxyFactory proxyFactory;
  -    //initialized in subclass, can't be final :-((
  -    protected EJBInvocation setContextInvocation;
  -    protected EJBInvocation unsetContextInvocation;
  +    private final Object containerId;
  +    private final EnterpriseBean instance;
       protected final Interceptor systemChain;
  +    private final EJBProxyFactory proxyFactory;
       private final BasicTimerService activeTimer;
       private final TimerService timerService;
  +    private final Set unshareableResources;
  +    private final Set applicationManagedSecurityResources;
  +
  +    private final Map connectionManagerMap = new HashMap();
   
       private BasicTimerService timerState = UnavailableTimerService.INSTANCE;
  +    private boolean dead = false;
  +    private int callDepth;
   
  -    public AbstractInstanceContext(Interceptor systemChain, Set 
unshareableResources, Set applicationManagedSecurityResources, EnterpriseBean 
instance, EJBProxyFactory proxyFactory, BasicTimerService basicTimerService) {
  -        this.unshareableResources = unshareableResources;
  -        this.applicationManagedSecurityResources = 
applicationManagedSecurityResources;
  +    public AbstractInstanceContext(Object containerId, EnterpriseBean 
instance, Interceptor systemChain, EJBProxyFactory proxyFactory, 
BasicTimerService basicTimerService, Set unshareableResources, Set 
applicationManagedSecurityResources) {
  +        this.containerId = containerId;
           this.instance = instance;
  -        this.proxyFactory = proxyFactory;
           this.systemChain = systemChain;
  +        this.proxyFactory = proxyFactory;
           this.activeTimer = basicTimerService;
           this.timerService = basicTimerService == null? null: new 
TimerServiceImpl(this);
  +        this.unshareableResources = unshareableResources;
  +        this.applicationManagedSecurityResources = 
applicationManagedSecurityResources;
       }
   
       public Object getId() {
           return null;
       }
   
  -    public void setId(Object id) {
  -    }
  -
       public Object getContainerId() {
  -        return null;
  +        return containerId;
       }
   
       public void associate() throws Throwable {
  +        if (dead) {
  +            throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
  +        }
       }
   
       public void flush() throws Throwable {
  +        if (dead) {
  +            throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
  +        }
       }
   
       public void beforeCommit() throws Throwable {
  +        if (dead) {
  +            throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
  +        }
       }
   
       public void afterCommit(boolean status) throws Throwable {
  +        if (dead) {
  +            throw new IllegalStateException("Context is dead: container=" + 
getContainerId() + ", id=" + getId());
  +        }
  +    }
  +
  +    public void unassociate() throws Throwable {
       }
   
       public Map getConnectionManagerMap() {
  @@ -108,14 +118,6 @@
           return proxyFactory;
       }
   
  -    public void setContext() throws Throwable {
  -        systemChain.invoke(setContextInvocation);
  -    }
  -
  -    public void unsetContext() throws Throwable {
  -        systemChain.invoke(unsetContextInvocation);
  -    }
  -
       public TimerService getTimerService() {
           return timerService;
       }
  @@ -130,6 +132,31 @@
           } else {
               timerState = UnavailableTimerService.INSTANCE;
           }
  +    }
  +
  +    public void die() {
  +        this.dead = true;
  +    }
  +
  +    public final boolean isDead() {
  +        return dead;
  +    }
  +
  +    public boolean isInCall() {
  +        return callDepth > 0;
  +    }
  +
  +    public void enter() {
  +        callDepth++;
  +    }
  +
  +    public void exit() {
  +        assert isInCall();
  +        callDepth--;
  +    }
  +
  +    public String toString() {
  +        return "[InstanceContext: container=" + getContainerId() + ", id=" + 
getId() + "]";
       }
   
   }
  
  
  
  1.6       +1 -2      
openejb/modules/core/src/java/org/openejb/EJBInstanceContext.java
  
  Index: EJBInstanceContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/EJBInstanceContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EJBInstanceContext.java   14 Feb 2005 18:32:12 -0000      1.5
  +++ EJBInstanceContext.java   25 Feb 2005 23:06:09 -0000      1.6
  @@ -73,5 +73,4 @@
   
       //sets timer method availability based on operation, returns old 
availability
       boolean setTimerState(EJBOperation operation);
  -
   }
  
  
  

Reply via email to