User: sparre  
  Date: 01/06/19 02:55:00

  Modified:    src/main/org/jboss/ejb EnterpriseContext.java
                        MessageDrivenEnterpriseContext.java
                        StatefulSessionEnterpriseContext.java
                        StatelessSessionEnterpriseContext.java
  Log:
  Only BMT bean may get a UserTransaction from the context.
  All others who try should get an IllegalStateException instead.
  
  Revision  Changes    Path
  1.33      +8 -4      jboss/src/main/org/jboss/ejb/EnterpriseContext.java
  
  Index: EnterpriseContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EnterpriseContext.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- EnterpriseContext.java    2001/06/18 20:01:21     1.32
  +++ EnterpriseContext.java    2001/06/19 09:55:00     1.33
  @@ -42,7 +42,7 @@
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>
  - *  @version $Revision: 1.32 $
  + *  @version $Revision: 1.33 $
    */
   public abstract class EnterpriseContext
   {
  @@ -331,9 +331,13 @@
      
         // TODO - how to handle this best?
         public UserTransaction getUserTransaction() 
  -       { 
  -         return new UserTransactionImpl(); 
  -       }
  +      { 
  +         // If not BMT, throw exception.
  +         // We default to the exception here, and override this method for
  +         // contexts of bean types that may be able to handle their own
  +         // transaction demarcation.
  +         throw new IllegalStateException("Not a BMT bean.");
  +      }
      }
      
       // Inner classes -------------------------------------------------
  
  
  
  1.5       +3 -5      jboss/src/main/org/jboss/ejb/MessageDrivenEnterpriseContext.java
  
  Index: MessageDrivenEnterpriseContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/MessageDrivenEnterpriseContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MessageDrivenEnterpriseContext.java       2001/06/18 20:01:21     1.4
  +++ MessageDrivenEnterpriseContext.java       2001/06/19 09:55:00     1.5
  @@ -38,7 +38,7 @@
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
    *  @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    */
   public class MessageDrivenEnterpriseContext
      extends EnterpriseContext
  @@ -173,10 +173,8 @@
               // NO transaction
               Logger.log("MessageDriven bean is not allowed to get a UserTransactio: 
transaction is containeremanaged");
               throw new IllegalStateException("MessageDriven bean is not allowed to 
get a UserTransactio: transaction is containeremanaged");
  -        }else {
  -            return super.getUserTransaction();
  -            
  -        }  
  +        } else
  +            return new UserTransactionImpl();
          }
      }
   }
  
  
  
  1.12      +37 -27    
jboss/src/main/org/jboss/ejb/StatefulSessionEnterpriseContext.java
  
  Index: StatefulSessionEnterpriseContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/StatefulSessionEnterpriseContext.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StatefulSessionEnterpriseContext.java     2001/06/18 20:01:21     1.11
  +++ StatefulSessionEnterpriseContext.java     2001/06/19 09:55:00     1.12
  @@ -17,13 +17,18 @@
   import javax.ejb.SessionBean;
   import javax.ejb.SessionContext;
   
  +import javax.transaction.UserTransaction;
  +
  +import org.jboss.metadata.SessionMetaData;
  +
  +
   /**
    *   <description> 
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Daniel OConnor</a>
  - *   @version $Revision: 1.11 $
  + *   @version $Revision: 1.12 $
    */
   public class StatefulSessionEnterpriseContext
      extends EnterpriseContext
  @@ -101,32 +106,30 @@
      }
   
      // Inner classes -------------------------------------------------
  +
      protected class StatefulSessionContextImpl
         extends EJBContextImpl
         implements SessionContext
      {
  -             public EJBObject getEJBObject()
  -             {
  -                            if 
(((StatefulSessionContainer)con).getContainerInvoker()==null)
  -                              throw new IllegalStateException( "No remote interface 
defined." );
  -
  -                     if (ejbObject == null) {
  -                             
  -                             try {
  -                                     
  -                                     ejbObject = 
((StatefulSessionContainer)con).getContainerInvoker().getStatefulSessionEJBObject(id); 
  -                             }
  -                             catch (RemoteException re) {
  -                                     // ...
  -                                     throw new IllegalStateException();
  -                             }
  -                     }       
  -                     
  -                     return ejbObject;
  -             }
  +      public EJBObject getEJBObject()
  +      {
  +         if (((StatefulSessionContainer)con).getContainerInvoker()==null)
  +            throw new IllegalStateException( "No remote interface defined." );
  +
  +         if (ejbObject == null) {
  +            try {
  +               ejbObject = 
((StatefulSessionContainer)con).getContainerInvoker().getStatefulSessionEJBObject(id); 
  +            } catch (RemoteException re) {
  +               // ...
  +               throw new IllegalStateException();
  +            }
  +         }   
  +
  +         return ejbObject;
  +      }
         
  -        public EJBLocalObject getEJBLocalObject()
  -        {
  +      public EJBLocalObject getEJBLocalObject()
  +      {
            if (con.getLocalHomeClass()==null)
               throw new IllegalStateException( "No local interface for bean." );
            if (ejbLocalObject == null)
  @@ -134,12 +137,19 @@
               ejbLocalObject = 
((StatefulSessionContainer)con).getLocalContainerInvoker().getStatefulSessionEJBLocalObject(id);
 
            }
            return ejbLocalObject;
  -        }
  +      }
   
  -             public Object getPrimaryKey()
  -             {
  +      public Object getPrimaryKey()
  +      {
            return id;
  -             }
  -     }
  +      }
  +
  +      public UserTransaction getUserTransaction()
  +      {
  +         if (((SessionMetaData)con.getBeanMetaData()).isContainerManagedTx())
  +            throw new IllegalStateException("Not a BMT bean.");
  +         return new UserTransactionImpl();
  +      }
  +   }
   }
   
  
  
  
  1.10      +28 -20    
jboss/src/main/org/jboss/ejb/StatelessSessionEnterpriseContext.java
  
  Index: StatelessSessionEnterpriseContext.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/StatelessSessionEnterpriseContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StatelessSessionEnterpriseContext.java    2001/06/18 20:01:21     1.9
  +++ StatelessSessionEnterpriseContext.java    2001/06/19 09:55:00     1.10
  @@ -19,13 +19,18 @@
   import javax.ejb.SessionBean;
   import javax.ejb.EJBException;
   
  +import javax.transaction.UserTransaction;
  +
  +import org.jboss.metadata.SessionMetaData;
  +
  +
   /**
    *   <description> 
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
    *  @author <a href="[EMAIL PROTECTED]">Sebastien Alborini</a>
  - *   @version $Revision: 1.9 $
  + *   @version $Revision: 1.10 $
    */
   public class StatelessSessionEnterpriseContext
      extends EnterpriseContext
  @@ -99,34 +104,37 @@
      {
         public EJBObject getEJBObject()
         {
  -               if (((StatelessSessionContainer)con).getContainerInvoker()==null)
  -                  throw new IllegalStateException( "No remote interface defined." );
  +         if (((StatelessSessionContainer)con).getContainerInvoker()==null)
  +            throw new IllegalStateException( "No remote interface defined." );
            
  -               if (ejbObject == null) {
  -                       
  -                             try {
  -                                     
  -                             ejbObject = 
((StatelessSessionContainer)con).getContainerInvoker().getStatelessSessionEJBObject(); 
  -                             }
  -                             catch (RemoteException re) {
  -                                     // ...
  -                                     throw new IllegalStateException();
  -                             }
  -                     }       
  +         if (ejbObject == null) {
  +            try {
  +               ejbObject = 
((StatelessSessionContainer)con).getContainerInvoker().getStatelessSessionEJBObject(); 
  +            } catch (RemoteException re) {
  +               // ...
  +               throw new IllegalStateException();
  +            }
  +         }   
       
  -             return ejbObject;
  +         return ejbObject;
         }
   
  -     public EJBLocalObject getEJBLocalObject()
  -     {
  +      public EJBLocalObject getEJBLocalObject()
  +      {
            if (con.getLocalHomeClass()==null)
               throw new IllegalStateException( "No local interface for bean." );
  -         if (ejbLocalObject == null)
  -         {
  +         if (ejbLocalObject == null) {
               ejbLocalObject = 
((StatelessSessionContainer)con).getLocalContainerInvoker().getStatelessSessionEJBLocalObject();
 
            }
            return ejbLocalObject;
  -     }
  +      }
  +
  +      public UserTransaction getUserTransaction()
  +      {
  +         if (((SessionMetaData)con.getBeanMetaData()).isContainerManagedTx())
  +            throw new IllegalStateException("Not a BMT bean.");
  +         return new UserTransactionImpl();
  +      }
      }
   }
   
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to