User: starksm 
  Date: 01/10/27 16:00:38

  Modified:    src/main/org/jboss/ejb/plugins Tag: Branch_2_4
                        BMPPersistenceManager.java
                        MessageDrivenTxInterceptorBMT.java
  Log:
  Change the transaction manager use to the javax.transaction.TransactionManager
  interface.
  Clean up exception casts made in the BMPPersistenceManager class.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.22.4.2  +112 -86   jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java
  
  Index: BMPPersistenceManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java,v
  retrieving revision 1.22.4.1
  retrieving revision 1.22.4.2
  diff -u -r1.22.4.1 -r1.22.4.2
  --- BMPPersistenceManager.java        2001/09/04 01:51:07     1.22.4.1
  +++ BMPPersistenceManager.java        2001/10/27 23:00:38     1.22.4.2
  @@ -1,13 +1,14 @@
   /*
  -* JBoss, the OpenSource EJB server
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * JBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.ejb.plugins;
   
   import java.lang.reflect.Method;
   import java.lang.reflect.InvocationTargetException;
  +import java.lang.reflect.UndeclaredThrowableException;
   import java.rmi.RemoteException;
   import java.rmi.ServerException;
   import java.util.Collection;
  @@ -31,41 +32,41 @@
   
   
   /**
  -*   <description>
  -*
  -*   @see <related>
  -*   @author Rickard �berg ([EMAIL PROTECTED])
  -*  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*   @version $Revision: 1.22.4.1 $
  -*/
  + *   <description>
  + *
  + *   @see <related>
  + *   @author Rickard �berg ([EMAIL PROTECTED])
  + *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  + *   @version $Revision: 1.22.4.2 $
  + */
   public class BMPPersistenceManager
   implements EntityPersistenceManager
   {
      // Constants -----------------------------------------------------
  -
  +   
      // Attributes ----------------------------------------------------
      EntityContainer con;
  -
  +   
      Method ejbLoad;
      Method ejbStore;
      Method ejbActivate;
      Method ejbPassivate;
      Method ejbRemove;
  -
  +   
      HashMap createMethods = new HashMap();
      HashMap postCreateMethods = new HashMap();
      HashMap finderMethods = new HashMap();
  -
  +   
      // Static --------------------------------------------------------
  -
  +   
      // Constructors --------------------------------------------------
  -
  +   
      // Public --------------------------------------------------------
      public void setContainer(Container c)
      {
         con = (EntityContainer)c;
      }
  -
  +   
      public void init()
      throws Exception
      {
  @@ -74,7 +75,7 @@
         ejbActivate = EntityBean.class.getMethod("ejbActivate", new Class[0]);
         ejbPassivate = EntityBean.class.getMethod("ejbPassivate", new Class[0]);
         ejbRemove = EntityBean.class.getMethod("ejbRemove", new Class[0]);
  -
  +      
         // Create cache of create methods
         if (con.getHomeClass() != null)
         {
  @@ -86,11 +87,11 @@
            Method[] methods = con.getLocalHomeClass().getMethods();
            createMethodCache( methods );
         }
  -
  +      
      }
      
      private void createMethodCache( Method[] methods )
  -      throws NoSuchMethodException
  +   throws NoSuchMethodException
      {
         for (int i = 0; i < methods.length; i++)
         {
  @@ -100,7 +101,7 @@
               postCreateMethods.put(methods[i], 
con.getBeanClass().getMethod("ejbPostCreate", methods[i].getParameterTypes()));
            }
         }
  -
  +      
         // Create cache of finder methods
         for (int i = 0; i < methods.length; i++)
         {
  @@ -110,25 +111,25 @@
            }
         }
      }
  -
  +   
      public void start()
      {
      }
  -
  +   
      public void stop()
      {
      }
  -
  +   
      public void destroy()
      {
      }
  -
  +   
      public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
  -   throws Exception
  +      throws Exception
      {
         Method createMethod = (Method)createMethods.get(m);
         Method postCreateMethod = (Method)postCreateMethods.get(m);
  -
  +      
         Object id = null;
         try
         {
  @@ -140,7 +141,7 @@
            throw new EJBException(e);
         } catch (InvocationTargetException ite)
         {
  -                     Throwable e = ite.getTargetException();
  +         Throwable e = ite.getTargetException();
            if (e instanceof CreateException)
            {
               // Rethrow exception
  @@ -160,37 +161,39 @@
            {
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
  -         } else
  +         }
  +         else
            {
  -            // Rethrow exception
  -            throw (Exception)e;
  +            throw new UndeclaredThrowableException(e);
            }
         }
   
         // set the id
         ctx.setId(id);
  -
  +      
         // Create a new CacheKey
         Object cacheKey = ((EntityCache) con.getInstanceCache()).createCacheKey( id );
  -
  +      
         // Give it to the context
         ctx.setCacheKey(cacheKey);
  -
  +      
         // Create EJBObject
  -        // Create EJBObject
  -     if (con.getContainerInvoker() != null)
  -      ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
  -     if (con.getLocalHomeClass() != null)
  -      
ctx.setEJBLocalObject(con.getLocalContainerInvoker().getEntityEJBLocalObject(cacheKey));
  -
  +      // Create EJBObject
  +      if (con.getContainerInvoker() != null)
  +         ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
  +      if (con.getLocalHomeClass() != null)
  +         
ctx.setEJBLocalObject(con.getLocalContainerInvoker().getEntityEJBLocalObject(cacheKey));
  +      
         try
         {
            postCreateMethod.invoke(ctx.getInstance(), args);
  -      } catch (IllegalAccessException e)
  +      }
  +      catch (IllegalAccessException e)
         {
            // Throw this as a bean exception...(?)
            throw new EJBException(e);
  -      } catch (InvocationTargetException ite)
  +      }
  +      catch (InvocationTargetException ite)
         {
            Throwable e = ite.getTargetException();
            if (e instanceof CreateException)
  @@ -212,30 +215,31 @@
            {
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
  -         } else
  +         }
  +         else
            {
  -            // Rethrow exception
  -            throw (Exception)e;
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
            }
         }
      }
  -
  +   
      public Object findEntity(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
  -   throws Exception
  +      throws Exception
      {
         // call the finder method
         Object objectId = callFinderMethod(finderMethod, args, ctx);
  -
  +      
         // get the cache, create a new key and return this new key
         return ((EntityCache)con.getInstanceCache()).createCacheKey( objectId );
      }
  -
  +   
      public Collection findEntities(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
  -   throws Exception
  +      throws Exception
      {
         // call the finder method
         Object result = callFinderMethod(finderMethod, args, ctx);
  -
  +      
         if (result == null)
         {
            // for EJB 1.0 compliance
  @@ -243,7 +247,7 @@
            // it returns null, so we return an empty collection
            return new ArrayList();
         }
  -
  +      
         if (result instanceof java.util.Enumeration)
         {
            // to preserve 1.0 spec compatiblity
  @@ -258,7 +262,7 @@
         }
         else if (result instanceof java.util.Collection)
         {
  -
  +         
            ArrayList array = new ArrayList(((Collection) result).size());
            Iterator enum =  ((Collection) result).iterator();
            while (enum.hasNext())
  @@ -275,9 +279,9 @@
            throw new RemoteException("result of finder method is not a valid return 
type: " + result.getClass());
         }
      }
  -
  +   
      public void activateEntity(EntityEnterpriseContext ctx)
  -   throws RemoteException
  +      throws RemoteException
      {
         try
         {
  @@ -304,11 +308,16 @@
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
            }
  +         else
  +         {
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
  +         }
         }
      }
  -
  +   
      public void loadEntity(EntityEnterpriseContext ctx)
  -   throws RemoteException
  +      throws RemoteException
      {
         try
         {
  @@ -335,11 +344,16 @@
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
            }
  +         else
  +         {
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
  +         }
         }
      }
  -
  +   
      public void storeEntity(EntityEnterpriseContext ctx)
  -   throws RemoteException
  +      throws RemoteException
      {
         //DEBUG       Logger.debug("Store entity");
         try
  @@ -367,11 +381,16 @@
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
            }
  +         else
  +         {
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
  +         }
         }
      }
  -
  +   
      public void passivateEntity(EntityEnterpriseContext ctx)
  -   throws RemoteException
  +      throws RemoteException
      {
         try
         {
  @@ -398,9 +417,14 @@
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
            }
  +         else
  +         {
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
  +         }
         }
      }
  -
  +   
      public void removeEntity(EntityEnterpriseContext ctx)
      throws RemoteException, RemoveException
      {
  @@ -434,17 +458,22 @@
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
            }
  +         else
  +         {
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
  +         }
         }
      }
      // Z implementation ----------------------------------------------
  -
  +   
      // Package protected ---------------------------------------------
  -
  +   
      // Protected -----------------------------------------------------
  -
  +   
      // Private -------------------------------------------------------
      private Object callFinderMethod(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
  -   throws Exception
  +      throws Exception
      {
         // Check if findByPrimaryKey
         // If so we check if the entity is in cache first
  @@ -458,27 +487,27 @@
            if (con.getInstanceCache().isActive(key))
               return args[0]; // Object is active -> it exists -> no need to call 
finder
         }
  -
  +      
         // get the finder method
         Method callMethod = (Method)finderMethods.get(finderMethod);
  -
  +      
         if (callMethod == null)
         {
            throw new RemoteException("couldn't find finder method in bean class. " + 
finderMethod.toString());
         }
  -
  +      
         // invoke the finder method
         Object result = null;
         try
         {
            result = callMethod.invoke(ctx.getInstance(), args);
         } catch (IllegalAccessException e)
  -             {
  -                     // Throw this as a bean exception...(?)
  -                     throw new EJBException(e);
  +      {
  +         // Throw this as a bean exception...(?)
  +         throw new EJBException(e);
         } catch (InvocationTargetException ite)
  -             {
  -                     Throwable e = ite.getTargetException();
  +      {
  +         Throwable e = ite.getTargetException();
            if (e instanceof FinderException)
            {
               // Rethrow exception
  @@ -498,20 +527,17 @@
            {
               // Wrap runtime exceptions
               throw new EJBException((Exception)e);
  -         } else
  +         }
  +         else
            {
  -            // Rethrow exception
  -            throw (Exception)e;
  +            Exception ex = new UndeclaredThrowableException(e);
  +            throw new EJBException(ex);
            }
         }
  -
  +      
         return result;
      }
  -
  -
  +   
  +   
      // Inner classes -------------------------------------------------
   }
  -
  -
  -
  -
  
  
  
  1.4.6.1   +135 -132  
jboss/src/main/org/jboss/ejb/plugins/MessageDrivenTxInterceptorBMT.java
  
  Index: MessageDrivenTxInterceptorBMT.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/MessageDrivenTxInterceptorBMT.java,v
  retrieving revision 1.4
  retrieving revision 1.4.6.1
  diff -u -r1.4 -r1.4.6.1
  --- MessageDrivenTxInterceptorBMT.java        2001/02/28 09:25:40     1.4
  +++ MessageDrivenTxInterceptorBMT.java        2001/10/27 23:00:38     1.4.6.1
  @@ -1,9 +1,9 @@
   /*
  -* jBoss, the OpenSource EJB server
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * jBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.ejb.plugins;
   
   import java.rmi.RemoteException;
  @@ -18,24 +18,24 @@
   
   import org.jboss.ejb.MessageDrivenEnterpriseContext;
   import org.jboss.ejb.MethodInvocation;
  -
   import org.jboss.logging.Logger;
  +
   /**
  -*   <description>
  -*
  -*   Stolen from TxInterceptorBMP
  -*   @see <related>
  -*   @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.4 $
  -*/
  + *   <description>
  + *
  + *   Stolen from TxInterceptorBMP
  + *   @see <related>
  + *   @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.4.6.1 $
  + */
   public class MessageDrivenTxInterceptorBMT
  -extends TxInterceptorBMT
  +   extends TxInterceptorBMT
   {
  -
  -
  -/**
  +   
  +   
  +   /**
       *   This method does invocation interpositioning of tx management
       *
       * MessageDriven specialication
  @@ -45,124 +45,127 @@
       * @return
       * @exception   Exception
       */
  -    public Object invoke(MethodInvocation mi) throws Exception {
  -
  -        // Store old UserTX
  -        Object oldUserTx = userTransaction.get();
  -        
  -     
  -     
  -     // 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
  -        Transaction t1 = tm.disassociateThread();
  -        
  -     //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);
  -        
  -     //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) {
  -                }
  -            }
  -        
  -            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) {
  -                }
  +   public Object invoke(MethodInvocation mi) throws Exception
  +   {
  +      
  +      // Store old UserTX
  +      Object oldUserTx = userTransaction.get();
  +      
  +      // retrieve the real userTransaction
  +      MessageDrivenEnterpriseContext ctx = 
(MessageDrivenEnterpriseContext)mi.getEnterpriseContext();
  +      UserTransaction ut = ctx.getMessageDrivenContext().getUserTransaction();
  +      userTransaction.set(ut);
  +      
  +      // 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.suspend();
  +      
  +      //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);
  +      
  +      //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.resume(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 (Error e)
  +         }
  +         
  +         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)
               {
  -            // 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);
  -                
  +         }
  +         
  +         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)
  +            {
               }
  -            
  -            
  -            
  -                // 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: 
  +         }
  +         
  +         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.resume(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)");
  -            }
  -            
  -            }
  -    }
  +               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)");
  +         }
  +         
  +      }
  +   }
   }
   
   
  
  
  

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

Reply via email to