djencks     2005/02/14 13:32:29

  Modified:    modules/core/src/java/org/openejb/entity
                        EntityContextImpl.java EntityInstanceContext.java
  Log:

  implement the amazing rules on when getTimerService() and the TimerService 
and Timer methods are available
  
  Revision  Changes    Path
  1.7       +35 -12    
openejb/modules/core/src/java/org/openejb/entity/EntityContextImpl.java
  
  Index: EntityContextImpl.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/EntityContextImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EntityContextImpl.java    10 Feb 2005 23:15:53 -0000      1.6
  +++ EntityContextImpl.java    14 Feb 2005 18:32:29 -0000      1.7
  @@ -62,11 +62,10 @@
   import org.openejb.EJBContextImpl;
   import org.openejb.EJBInstanceContext;
   import org.openejb.EJBOperation;
  +import org.openejb.timer.TimerState;
   import org.apache.geronimo.transaction.context.TransactionContextManager;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class EntityContextImpl extends EJBContextImpl implements 
EntityContext {
  @@ -76,7 +75,14 @@
   
       public void setState(EJBOperation operation) {
           state = states[operation.getOrdinal()];
  -        assert (state != null) : "Invalid EJBOperation for Stateless 
SessionBean, ordinal=" + operation.getOrdinal();
  +        assert (state != null) : "Invalid EJBOperation for EntityBean, 
ordinal=" + operation.getOrdinal();
  +        
context.setTimerServiceAvailable(timerServiceAvailable[operation.getOrdinal()]);
  +    }
  +
  +    public boolean setTimerState(EJBOperation operation) {
  +        boolean oldTimerState = TimerState.getTimerState();
  +        
TimerState.setTimerState(timerMethodsAvailable[operation.getOrdinal()]);
  +        return oldTimerState;
       }
   
       public Object getPrimaryKey() throws IllegalStateException {
  @@ -197,10 +203,6 @@
           public Object getPrimaryKey(EJBInstanceContext context) {
               throw new IllegalStateException("getPrimaryKey() cannot be 
called from ejbHome");
           }
  -
  -        public TimerService getTimerService(EJBInstanceContext context) {
  -            throw new IllegalStateException("getTimerService() cannot be 
called from set/unsetEntityContext");
  -        }
       };
   
       public static EntityContextState EJBPOSTCREATE = new 
EntityContextState() {
  @@ -239,10 +241,6 @@
           public Object getPrimaryKey(EJBInstanceContext context) {
               throw new IllegalStateException("getPrimaryKey() cannot be 
called from ejbHome");
           }
  -
  -        public TimerService getTimerService(EJBInstanceContext context) {
  -            throw new IllegalStateException("getTimerService() cannot be 
called from set/unsetEntityContext");
  -        }
       };
   
       public static EntityContextState EJBACTIVATE = new EntityContextState() {
  @@ -287,4 +285,29 @@
           states[EJBOperation.BIZMETHOD.getOrdinal()] = BIZ_INTERFACE;
           states[EJBOperation.TIMEOUT.getOrdinal()] = EJBTIMEOUT;
       }
  +
  +    private static final boolean timerServiceAvailable[] = new 
boolean[EJBOperation.MAX_ORDINAL];
  +
  +    static {
  +        timerServiceAvailable[EJBOperation.EJBCREATE.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.EJBPOSTCREATE.getOrdinal()] = 
true;
  +        timerServiceAvailable[EJBOperation.EJBREMOVE.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.EJBFIND.getOrdinal()] = 
true;//TODO ??? don't know
  +        timerServiceAvailable[EJBOperation.EJBHOME.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.EJBACTIVATE.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.EJBLOAD.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.BIZMETHOD.getOrdinal()] = true;
  +        timerServiceAvailable[EJBOperation.TIMEOUT.getOrdinal()] = true;
  +    }
  +
  +    private static final boolean timerMethodsAvailable[] = new 
boolean[EJBOperation.MAX_ORDINAL];
  +
  +    static {
  +        timerMethodsAvailable[EJBOperation.EJBPOSTCREATE.getOrdinal()] = 
true;
  +        timerMethodsAvailable[EJBOperation.EJBREMOVE.getOrdinal()] = true;
  +        timerMethodsAvailable[EJBOperation.EJBLOAD.getOrdinal()] = true;
  +        timerMethodsAvailable[EJBOperation.BIZMETHOD.getOrdinal()] = true;
  +        timerMethodsAvailable[EJBOperation.TIMEOUT.getOrdinal()] = true;
  +    }
  +
   }
  
  
  
  1.10      +5 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- EntityInstanceContext.java        5 Feb 2005 02:36:23 -0000       1.9
  +++ EntityInstanceContext.java        14 Feb 2005 18:32:29 -0000      1.10
  @@ -105,6 +105,10 @@
           entityContext.setState(operation);
       }
   
  +    public boolean setTimerState(EJBOperation operation) {
  +        return entityContext.setTimerState(operation);
  +    }
  +
       public EntityContext getEntityContext() {
           return entityContext;
       }
  
  
  

Reply via email to