User: oleg    
  Date: 01/01/30 07:59:15

  Modified:    src/main/org/jboss/ejb/plugins
                        MessageDrivenTxInterceptorBMT.java
                        TxInterceptorBMT.java
  Log:
  Minor improvement to RuntimeException handling
  
  Revision  Changes    Path
  1.3       +110 -103  
jboss/src/main/org/jboss/ejb/plugins/MessageDrivenTxInterceptorBMT.java
  
  Index: MessageDrivenTxInterceptorBMT.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/MessageDrivenTxInterceptorBMT.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MessageDrivenTxInterceptorBMT.java        2001/01/03 08:28:31     1.2
  +++ MessageDrivenTxInterceptorBMT.java        2001/01/30 15:59:14     1.3
  @@ -14,6 +14,8 @@
   import javax.transaction.RollbackException;
   import javax.transaction.UserTransaction;
   
  +import javax.ejb.EJBException;
  +
   import org.jboss.ejb.MessageDrivenEnterpriseContext;
   import org.jboss.ejb.MethodInvocation;
   
  @@ -26,7 +28,7 @@
   *   @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
   *   @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
   *   @author Peter Antman ([EMAIL PROTECTED])
  -*   @version $Revision: 1.2 $
  +*   @version $Revision: 1.3 $
   */
   public class MessageDrivenTxInterceptorBMT
   extends TxInterceptorBMT
  @@ -45,116 +47,121 @@
       */
       public Object invoke(MethodInvocation mi) throws Exception {
   
  -             // Store old UserTX
  +        // Store old UserTX
           Object oldUserTx = userTransaction.get();
  -             
  -     
  -     
  -     // retrieve the real userTransaction
  -     
userTransaction.set(((MessageDrivenEnterpriseContext)mi.getEnterpriseContext()).getMessageDrivenContext().getUserTransaction());
  -                     
  +        
  +    
  +    
  +    // retrieve the real userTransaction
  +    
userTransaction.set(((MessageDrivenEnterpriseContext)mi.getEnterpriseContext()).getMessageDrivenContext().getUserTransaction());
  +            
  +        
           
  -             
           // t1 refers to the client transaction (spec ejb1.1, 11.6.1, p174)
  -             // this is necessary for optimized (inVM) calls: threads come 
associated with the client transaction
  +        // this is necessary for optimized (inVM) calls: threads come associated 
with the client transaction
           Transaction t1 = tm.disassociateThread();
  -             
  -//DEBUG              Logger.debug("TxInterceptorBMT disassociate" + ((t1==null) ? 
"null": Integer.toString(t1.hashCode())));
  -     
  +        
  +//DEBUG     Logger.debug("TxInterceptorBMT disassociate" + ((t1==null) ? "null": 
Integer.toString(t1.hashCode())));
  +    
           // t2 refers to the instance transaction (spec ejb1.1, 11.6.1, p174) 
           Transaction t2 = mi.getEnterpriseContext().getTransaction();
  -     
  -     // This is BMT so the transaction is dictated by the Bean, the 
MethodInvocation follows
  -     mi.setTransaction(t2);
  +    
  +    // This is BMT so the transaction is dictated by the Bean, the MethodInvocation 
follows
  +    mi.setTransaction(t2);
  +        
  +    //DEBUG Logger.debug("TxInterceptorBMT t2 in context" + ((t2==null) ? "null": 
Integer.toString(t2.hashCode())));
           
  -     //DEBUG Logger.debug("TxInterceptorBMT t2 in context" + ((t2==null) ? "null": 
Integer.toString(t2.hashCode())));
  -             
           try {
  -         
  -         if (t2 != null) {
  -             
  -                             // associate the transaction to the thread
  -             tm.associateThread(t2);
  -             
  -         }
  -         
  -         return getNext().invoke(mi);
  -         
  -     } catch (RuntimeException e)
  -         {
  -             // EJB 2.0 17.3, table 16
  -             if (mi.getEnterpriseContext().getTransaction() != null) {
  -                 try {
  -                                     
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                 } catch (IllegalStateException ex) {
  -                 }
  -             }
  -             
  -             throw new ServerException("Transaction rolled back", e);        
  -         } catch (RemoteException e)
  -             {
  -                 // EJB 2.0 17.3, table 16
  -                 if (mi.getEnterpriseContext().getTransaction() != null) {
  -                     try {
  -                         
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                     } catch (IllegalStateException ex) {
  -                     }
  -                 }
  -                 
  -                 throw new ServerException("Transaction rolled back", e);    
  -             } catch (Error e)
  -                 {
  -                     // EJB 2.0 17.3, table 16
  -                     if (mi.getEnterpriseContext().getTransaction() != null) {
  -                         try {
  -                             
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                         } catch (IllegalStateException ex) {
  -                         }
  -                     }
  -                     
  -                     throw new ServerException("Transaction rolled 
back:"+e.getMessage());   
  -                 } finally {
  -                     
  -                     // Reset user Tx
  -                     userTransaction.set(oldUserTx);
  -                     
  -                     if (t1 != null) {
  -                         
  -                             // DEBUG Logger.debug("TxInterceptorBMT reassociating 
client tx " + t1.hashCode());
  -                         //DEBUG                             
Logger.debug("TxInterceptorBMT reassociating client tx " + t1.hashCode());
  -                         
  -                             // reassociate the previous transaction before 
returning
  -                         tm.associateThread(t1);
  -                         
  -                     }
  -                     
  -                     
  -                     
  -                             // t3 is the transaction associated with the context 
at the end of the call
  -                     Transaction t3 = mi.getEnterpriseContext().getTransaction();
  -                     
  -                     //DEBUG                         Logger.debug("in TxIntBMT " + 
t3);
  -                     
  -                             // for a stateless sessionbean the transaction should 
be completed at the end of the call
  -                     if (t3 != null) switch (t3.getStatus()) {
  -                     case Status.STATUS_ACTIVE: 
  -                         case Status.STATUS_COMMITTING: 
  -                     case Status.STATUS_MARKED_ROLLBACK: 
  -                     case Status.STATUS_PREPARING: 
  -                     case Status.STATUS_ROLLING_BACK:
  -                         
  -                         t3.rollback();
  -                         
  -                     case Status.STATUS_PREPARED: 
  -                         
  -                             // cf ejb1.1 11.6.1
  -                         Logger.error("Application error: BMT stateless bean " + 
container.getBeanMetaData().getEjbName() + " should complete transactions before 
returning (ejb1.1 spec, 11.6.1)");
  -                         
  -                         // the instance interceptor will discard the instance
  -                         throw new RemoteException("Application error: BMT 
stateless bean " + container.getBeanMetaData().getEjbName() + " should complete 
transactions before returning (ejb1.1 spec, 11.6.1)");
  -                     }
  -                     
  -                 }
  +        
  +        if (t2 != null) {
  +        
  +                // associate the transaction to the thread
  +        tm.associateThread(t2);
  +        
  +        }
  +        
  +        return getNext().invoke(mi);
  +        
  +    } catch (RuntimeException e)
  +        {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                        
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +        
  +            if (e instanceof EJBException) {
  +                throw new ServerException("Transaction rolled back",
  +                                          ((EJBException) 
e).getCausedByException());
  +            } else {
  +                throw new ServerException("Transaction rolled back", e);
  +            }
  +        } catch (RemoteException e)
  +        {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                    mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +            
  +            throw new ServerException("Transaction rolled back", e);    
  +        } catch (Error e)
  +            {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +            
  +            throw new ServerException("Transaction rolled back:"+e.getMessage());   
  +            } finally {
  +            
  +            // Reset user Tx
  +            userTransaction.set(oldUserTx);
  +            
  +            if (t1 != null) {
  +                
  +                // DEBUG Logger.debug("TxInterceptorBMT reassociating client tx " + 
t1.hashCode());
  +                //DEBUG             Logger.debug("TxInterceptorBMT reassociating 
client tx " + t1.hashCode());
  +                
  +                // reassociate the previous transaction before returning
  +                tm.associateThread(t1);
  +                
  +            }
  +            
  +            
  +            
  +                // t3 is the transaction associated with the context at the end of 
the call
  +            Transaction t3 = mi.getEnterpriseContext().getTransaction();
  +            
  +            //DEBUG             Logger.debug("in TxIntBMT " + t3);
  +            
  +                // for a stateless sessionbean the transaction should be completed 
at the end of the call
  +            if (t3 != null) switch (t3.getStatus()) {
  +            case Status.STATUS_ACTIVE: 
  +                case Status.STATUS_COMMITTING: 
  +            case Status.STATUS_MARKED_ROLLBACK: 
  +            case Status.STATUS_PREPARING: 
  +            case Status.STATUS_ROLLING_BACK:
  +                
  +                t3.rollback();
  +                
  +            case Status.STATUS_PREPARED: 
  +                
  +                // cf ejb1.1 11.6.1
  +                Logger.error("Application error: BMT stateless bean " + 
container.getBeanMetaData().getEjbName() + " should complete transactions before 
returning (ejb1.1 spec, 11.6.1)");
  +                
  +                // the instance interceptor will discard the instance
  +                throw new RemoteException("Application error: BMT stateless bean " 
+ container.getBeanMetaData().getEjbName() + " should complete transactions before 
returning (ejb1.1 spec, 11.6.1)");
  +            }
  +            
  +            }
       }
   }
   
  
  
  
  1.12      +220 -210  jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java
  
  Index: TxInterceptorBMT.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TxInterceptorBMT.java     2000/12/07 15:44:25     1.11
  +++ TxInterceptorBMT.java     2001/01/30 15:59:14     1.12
  @@ -50,7 +50,7 @@
   *   @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
   *   @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
   *   @author Peter Antman ([EMAIL PROTECTED])
  -*   @version $Revision: 1.11 $
  +*   @version $Revision: 1.12 $
   */
   public class TxInterceptorBMT
   extends AbstractInterceptor
  @@ -62,10 +62,10 @@
       
       // lookup on java:comp/UserTransaction should be redirected to
       //   sessionContext.getUserTransaction()
  -     // The ThreadLocal associates the thread to the UserTransaction 
  -     ThreadLocal userTransaction = new ThreadLocal(); 
  +    // The ThreadLocal associates the thread to the UserTransaction 
  +    ThreadLocal userTransaction = new ThreadLocal(); 
       
  -     protected Container container;
  +    protected Container container;
   
       // Static --------------------------------------------------------
       
  @@ -83,26 +83,26 @@
       }
       
       // Interceptor implementation --------------------------------------
  -     public void init()
  +    public void init()
       throws Exception
       {
           // Store TM reference locally
           tm = (TxManager) getContainer().getTransactionManager();
           
  -     // bind java:comp/UserTransaction
  -             RefAddr refAddr = new RefAddr("userTransaction") {
  -             public Object getContent() {
  +        // bind java:comp/UserTransaction
  +        RefAddr refAddr = new RefAddr("userTransaction") {
  +            public Object getContent() {
                   return userTransaction;
  -                     }
  -             };
  -             
  -             Reference ref = new Reference("javax.transaction.UserTransaction", 
  -                                                                       refAddr, 
  -                                                                       new 
UserTxFactory().getClass().getName(), 
  -                                                                       null);
  -             ((Context)new 
InitialContext().lookup("java:comp/")).bind("UserTransaction", ref);
  -                     
  -     }
  +            }
  +        };
  +        
  +        Reference ref = new Reference("javax.transaction.UserTransaction", 
  +                                      refAddr, 
  +                                      new UserTxFactory().getClass().getName(), 
  +                                      null);
  +        ((Context)new 
InitialContext().lookup("java:comp/")).bind("UserTransaction", ref);
  +            
  +    }
   
       public void stop()
       {
  @@ -120,84 +120,89 @@
       throws Exception
       {
           // set the threadlocal to the userTransaction of the instance
  -             // (mi has the sessioncontext from the previous interceptor)
  -             if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
  -                     
  -                     // Save old userTx
  -                     Object oldUserTx = userTransaction.get();
  -                     
  -                     // retrieve the real userTransaction
  -                     
userTransaction.set(((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  -             
  -                     // t1 refers to the client transaction (spec ejb1.1, 11.6.1, 
p174)
  -                     // this is necessary for optimized (inVM) calls: threads come 
associated with the client transaction
  -                     Transaction t1 = tm.disassociateThread();
  -                     
  -                     // t2 refers to the instance transaction (spec ejb1.1, 11.6.1, 
p174) 
  -                     Transaction t2 = mi.getEnterpriseContext().getTransaction();
  -                     
  -                     try {
  -                             
  -                             if (t2 != null) {
  -                                     
  -                                     // associate the transaction to the thread
  -                                     tm.associateThread(t2);
  -                             
  -                             }
  -                             
  -                             return getNext().invokeHome(mi);
  -                     
  -                     } catch (RuntimeException e)
  -                     {
  -                             // EJB 2.0 17.3, table 16
  -                             if (mi.getEnterpriseContext().getTransaction() != 
null) {
  -                                     try {
  -                                             
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                                     } catch (IllegalStateException ex) {
  -                                     }
  -                             }
  -                             
  -                             throw new ServerException("Transaction rolled back", 
e);        
  -                     } catch (RemoteException e)
  -                     {
  -                             // EJB 2.0 17.3, table 16
  -                             if (mi.getEnterpriseContext().getTransaction() != 
null) {
  -                                     try {
  -                                             
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                                     } catch (IllegalStateException ex) {
  -                                     }
  -                             }
  -                     
  -                             throw new ServerException("Transaction rolled back", 
e);        
  -                     } catch (Error e)
  -                     {
  -                             // EJB 2.0 17.3, table 16
  -                             if (mi.getEnterpriseContext().getTransaction() != 
null) {
  -                                     try {
  -                                             
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                                     } catch (IllegalStateException ex) {
  -                                     }
  -                             }
  -                     
  -                             throw new ServerException("Transaction rolled 
back:"+e.getMessage());   
  -                     } finally {
  -                             
  -                             // Reset user Tx
  -                             userTransaction.set(oldUserTx);
  -                             
  -                             if (t1 != null) {
  -                                     
  -                                     // reassociate the previous transaction before 
returning
  -                                     tm.associateThread(t1);
  -                             
  -                             }
  -                     }
  -             } else {
  -                     
  -                     // stateless: no context, no transaction, no call to the 
instance
  -                     
  -                     return getNext().invokeHome(mi);
  -             }
  +        // (mi has the sessioncontext from the previous interceptor)
  +        if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
  +            
  +            // Save old userTx
  +            Object oldUserTx = userTransaction.get();
  +            
  +            // retrieve the real userTransaction
  +            
userTransaction.set(((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  +        
  +            // t1 refers to the client transaction (spec ejb1.1, 11.6.1, p174)
  +            // this is necessary for optimized (inVM) calls: threads come 
associated with the client transaction
  +            Transaction t1 = tm.disassociateThread();
  +            
  +            // t2 refers to the instance transaction (spec ejb1.1, 11.6.1, p174) 
  +            Transaction t2 = mi.getEnterpriseContext().getTransaction();
  +            
  +            try {
  +                
  +                if (t2 != null) {
  +                    
  +                    // associate the transaction to the thread
  +                    tm.associateThread(t2);
  +                
  +                }
  +                
  +                return getNext().invokeHome(mi);
  +            
  +            } catch (RuntimeException e)
  +            {
  +                // EJB 2.0 17.3, table 16
  +                if (mi.getEnterpriseContext().getTransaction() != null) {
  +                    try {
  +                        
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                    } catch (IllegalStateException ex) {
  +                    }
  +                }
  +                
  +                if (e instanceof EJBException) {
  +                    throw new ServerException("Transaction rolled back",
  +                                              ((EJBException) 
e).getCausedByException());    
  +                } else {
  +                    throw new ServerException("Transaction rolled back", e);    
  +                }
  +            } catch (RemoteException e)
  +            {
  +                // EJB 2.0 17.3, table 16
  +                if (mi.getEnterpriseContext().getTransaction() != null) {
  +                    try {
  +                        
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                    } catch (IllegalStateException ex) {
  +                    }
  +                }
  +            
  +                throw new ServerException("Transaction rolled back", e);    
  +            } catch (Error e)
  +            {
  +                // EJB 2.0 17.3, table 16
  +                if (mi.getEnterpriseContext().getTransaction() != null) {
  +                    try {
  +                        
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                    } catch (IllegalStateException ex) {
  +                    }
  +                }
  +            
  +                throw new ServerException("Transaction rolled 
back:"+e.getMessage());   
  +            } finally {
  +                
  +                // Reset user Tx
  +                userTransaction.set(oldUserTx);
  +                
  +                if (t1 != null) {
  +                    
  +                    // reassociate the previous transaction before returning
  +                    tm.associateThread(t1);
  +                
  +                }
  +            }
  +        } else {
  +            
  +            // stateless: no context, no transaction, no call to the instance
  +            
  +            return getNext().invokeHome(mi);
  +        }
           
           
       }
  @@ -213,143 +218,148 @@
       */
       public Object invoke(MethodInvocation mi) throws Exception {
   
  -             // Store old UserTX
  +        // Store old UserTX
           Object oldUserTx = userTransaction.get();
  -             
  +        
           // set the threadlocal to the userTransaction of the instance
  -             // (mi has the sessioncontext from the previous interceptor)
  -             if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
  -                     
  -                     // retrieve the real userTransaction
  -                     
userTransaction.set(((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  -             
  -             } else {
  -                     
  -                     // retrieve the real userTransaction
  -                     
userTransaction.set(((StatelessSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  -             }
  +        // (mi has the sessioncontext from the previous interceptor)
  +        if (((SessionMetaData)container.getBeanMetaData()).isStateful()) {
  +            
  +            // retrieve the real userTransaction
  +            
userTransaction.set(((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  +        
  +        } else {
  +            
  +            // retrieve the real userTransaction
  +            
userTransaction.set(((StatelessSessionEnterpriseContext)mi.getEnterpriseContext()).getSessionContext().getUserTransaction());
  +        }
  +        
           
  -             
           // t1 refers to the client transaction (spec ejb1.1, 11.6.1, p174)
  -             // this is necessary for optimized (inVM) calls: threads come 
associated with the client transaction
  +        // this is necessary for optimized (inVM) calls: threads come associated 
with the client transaction
           Transaction t1 = tm.disassociateThread();
  -             
  -//DEBUG              Logger.debug("TxInterceptorBMT disassociate" + ((t1==null) ? 
"null": Integer.toString(t1.hashCode())));
  -             
  +        
  +//DEBUG     Logger.debug("TxInterceptorBMT disassociate" + ((t1==null) ? "null": 
Integer.toString(t1.hashCode())));
  +        
           // t2 refers to the instance transaction (spec ejb1.1, 11.6.1, p174) 
           Transaction t2 = mi.getEnterpriseContext().getTransaction();
  -             
  -             // This is BMT so the transaction is dictated by the Bean, the 
MethodInvocation follows
  -             mi.setTransaction(t2);
  +        
  +        // This is BMT so the transaction is dictated by the Bean, the 
MethodInvocation follows
  +        mi.setTransaction(t2);
           
   //DEBUG Logger.debug("TxInterceptorBMT t2 in context" + ((t2==null) ? "null": 
Integer.toString(t2.hashCode())));
  -             
  +        
           try {
  -                     
  -                     if (t2 != null) {
  -                             
  -                             // associate the transaction to the thread
  -                             tm.associateThread(t2);
  -                                                             
  -                     }
  -                     
  -                     return getNext().invoke(mi);
  -                     
  -             } catch (RuntimeException e)
  -             {
  -                     // EJB 2.0 17.3, table 16
  -                     if (mi.getEnterpriseContext().getTransaction() != null) {
  -                             try {
  -                                     
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                             } catch (IllegalStateException ex) {
  -                             }
  -                     }
  -                     
  -                     throw new ServerException("Transaction rolled back", e);       
 
  -             } catch (RemoteException e)
  -             {
  -                     // EJB 2.0 17.3, table 16
  -                     if (mi.getEnterpriseContext().getTransaction() != null) {
  -                             try {
  -                                     
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                             } catch (IllegalStateException ex) {
  -                             }
  -                     }
  -             
  -                     throw new ServerException("Transaction rolled back", e);       
 
  -             } catch (Error e)
  -             {
  -                     // EJB 2.0 17.3, table 16
  -                     if (mi.getEnterpriseContext().getTransaction() != null) {
  -                             try {
  -                                     
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  -                             } catch (IllegalStateException ex) {
  -                             }
  -                     }
  -             
  -                     throw new ServerException("Transaction rolled 
back:"+e.getMessage());   
  -             } finally {
  -                     
  -                     // Reset user Tx
  -                     userTransaction.set(oldUserTx);
  -                     
  -                     if (t1 != null) {
  -                             
  -                             // DEBUG Logger.debug("TxInterceptorBMT reassociating 
client tx " + t1.hashCode());
  -//DEBUG                              Logger.debug("TxInterceptorBMT reassociating 
client tx " + t1.hashCode());
  -                             
  -                             // reassociate the previous transaction before 
returning
  -                             tm.associateThread(t1);
  -                             
  -                     }
  -                     
  -                     if 
(((SessionMetaData)container.getBeanMetaData()).isStateless()) {
  +            
  +            if (t2 != null) {
  +                
  +                // associate the transaction to the thread
  +                tm.associateThread(t2);
  +                                
  +            }
  +            
  +            return getNext().invoke(mi);
  +            
  +        } catch (RuntimeException e)
  +        {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                    mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +            
  +            if (e instanceof EJBException) {
  +                throw new ServerException("Transaction rolled back",
  +                                          ((EJBException) 
e).getCausedByException());
  +            } else {
  +                throw new ServerException("Transaction rolled back", e);
  +            }
  +        } catch (RemoteException e)
  +        {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                    mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +        
  +            throw new ServerException("Transaction rolled back", e);    
  +        } catch (Error e)
  +        {
  +            // EJB 2.0 17.3, table 16
  +            if (mi.getEnterpriseContext().getTransaction() != null) {
  +                try {
  +                    mi.getEnterpriseContext().getTransaction().setRollbackOnly();
  +                } catch (IllegalStateException ex) {
  +                }
  +            }
  +        
  +            throw new ServerException("Transaction rolled back:"+e.getMessage());   
  +        } finally {
  +            
  +            // Reset user Tx
  +            userTransaction.set(oldUserTx);
  +            
  +            if (t1 != null) {
  +                
  +                // DEBUG Logger.debug("TxInterceptorBMT reassociating client tx " + 
t1.hashCode());
  +//DEBUG             Logger.debug("TxInterceptorBMT reassociating client tx " + 
t1.hashCode());
  +                
  +                // reassociate the previous transaction before returning
  +                tm.associateThread(t1);
  +                
  +            }
  +            
  +            if (((SessionMetaData)container.getBeanMetaData()).isStateless()) {
   
  -                             // t3 is the transaction associated with the context 
at the end of the call
  -                             Transaction t3 = 
mi.getEnterpriseContext().getTransaction();
  -                             
  -//DEBUG                              Logger.debug("in TxIntBMT " + t3);
  -                             
  -                             // for a stateless sessionbean the transaction should 
be completed at the end of the call
  -                         if (t3 != null) switch (t3.getStatus()) {
  -                                     case Status.STATUS_ACTIVE: 
  -                             case Status.STATUS_COMMITTING: 
  -                             case Status.STATUS_MARKED_ROLLBACK: 
  -                             case Status.STATUS_PREPARING: 
  -                             case Status.STATUS_ROLLING_BACK:
  -                                         
  -                                             t3.rollback();
  -                                     
  -                                     case Status.STATUS_PREPARED: 
  -                             
  -                                             // cf ejb1.1 11.6.1
  -                                             Logger.error("Application error: BMT 
stateless bean " + container.getBeanMetaData().getEjbName() + " should complete 
transactions before returning (ejb1.1 spec, 11.6.1)");
  -                                         
  -                                             // the instance interceptor will 
discard the instance
  -                                             throw new RemoteException("Application 
error: BMT stateless bean " + container.getBeanMetaData().getEjbName() + " should 
complete transactions before returning (ejb1.1 spec, 11.6.1)");
  -                             }
  -                     }
  -             }
  +                // t3 is the transaction associated with the context at the end of 
the call
  +                Transaction t3 = mi.getEnterpriseContext().getTransaction();
  +                
  +//DEBUG             Logger.debug("in TxIntBMT " + t3);
  +                
  +                // for a stateless sessionbean the transaction should be completed 
at the end of the call
  +                if (t3 != null) switch (t3.getStatus()) {
  +                    case Status.STATUS_ACTIVE: 
  +                    case Status.STATUS_COMMITTING: 
  +                    case Status.STATUS_MARKED_ROLLBACK: 
  +                    case Status.STATUS_PREPARING: 
  +                    case Status.STATUS_ROLLING_BACK:
  +                        
  +                        t3.rollback();
  +                    
  +                    case Status.STATUS_PREPARED: 
  +                    
  +                        // cf ejb1.1 11.6.1
  +                        Logger.error("Application error: BMT stateless bean " + 
container.getBeanMetaData().getEjbName() + " should complete transactions before 
returning (ejb1.1 spec, 11.6.1)");
  +                        
  +                        // the instance interceptor will discard the instance
  +                        throw new RemoteException("Application error: BMT stateless 
bean " + container.getBeanMetaData().getEjbName() + " should complete transactions 
before returning (ejb1.1 spec, 11.6.1)");
  +                }
  +            }
  +        }
       }
       
       // Protected  ----------------------------------------------------
       
       // Inner classes -------------------------------------------------
       
  -     public static class UserTxFactory implements ObjectFactory {
  +    public static class UserTxFactory implements ObjectFactory {
           public Object getObjectInstance(Object ref,
                                           Name name,
                                           Context nameCtx,
                                           Hashtable environment)
                                           throws Exception 
  -             {
  -                     
  +        {
  +            
               // the ref is a list with only one refAddr whose content is the 
threadlocal
  -                     ThreadLocal threadLocal = 
(ThreadLocal)((Reference)ref).get(0).getContent();
  -                     
  -                     // the threadlocal holds the UserTransaction
  -                     // we can now return the userTx, calls on it will indirect on 
the right context
  -                     return threadLocal.get();
  +            ThreadLocal threadLocal = 
(ThreadLocal)((Reference)ref).get(0).getContent();
  +            
  +            // the threadlocal holds the UserTransaction
  +            // we can now return the userTx, calls on it will indirect on the right 
context
  +            return threadLocal.get();
      
           }
       }
  
  
  

Reply via email to