User: starksm 
  Date: 02/02/12 00:15:36

  Modified:    src/main/org/jboss/ejb/plugins
                        StatefulSessionInstanceCache.java
                        StatefulSessionInstanceInterceptor.java
                        TxInterceptorCMT.java
  Log:
  Change all use of log.debug to log.trace for method that are in the
  invocation path or associated with timers. Debug is only for O(1)
  messages.
  
  Revision  Changes    Path
  1.15      +5 -3      
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceCache.java
  
  Index: StatefulSessionInstanceCache.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceCache.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StatefulSessionInstanceCache.java 26 Nov 2001 03:12:25 -0000      1.14
  +++ StatefulSessionInstanceCache.java 12 Feb 2002 08:15:36 -0000      1.15
  @@ -30,7 +30,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Simone Bordet</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - * @version $Revision: 1.14 $
  + * @version $Revision: 1.15 $
    */
   public class StatefulSessionInstanceCache
       extends AbstractInstanceCache
  @@ -125,7 +125,8 @@
               if (now - passivationTime > maxLifeAfterPassivation)
               {
                   store.removePassivated(key);
  -                log(key);
  +                if( log.isTraceEnabled() )
  +                  log(key);
                   // Must use the iterator to remove, otherwise
                   // ConcurrentModificationException is thrown
                   entries.remove();
  @@ -144,7 +145,8 @@
           m_buffer.append(m_container.getBeanMetaData().getEjbName());
           m_buffer.append("' with id = ");
           m_buffer.append(key);
  -        log.debug(m_buffer.toString());
  +        if( log.isTraceEnabled() )
  +         log.trace(m_buffer.toString());
   
           if (isJMSMonitoringEnabled())
           {
  
  
  
  1.28      +127 -103  
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
  
  Index: StatefulSessionInstanceInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- StatefulSessionInstanceInterceptor.java   5 Feb 2002 22:03:27 -0000       1.27
  +++ StatefulSessionInstanceInterceptor.java   12 Feb 2002 08:15:36 -0000      1.28
  @@ -31,13 +31,13 @@
   import org.jboss.security.SecurityAssociation;
   
   /**
  - * This container acquires the given instance. 
  + * This container acquires the given instance.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>
  - * @version $Revision: 1.27 $
  + * @version $Revision: 1.28 $
    *
    * <p><b>Revisions:</b>
    * <p><b>20010704 marcf</b>
  @@ -53,48 +53,50 @@
      extends AbstractInterceptor
   {
      // Constants ----------------------------------------------------
  -     
  +   
      // Attributes ---------------------------------------------------
  -
  +   
      /** Instance logger. */
      protected Logger log = Logger.getLogger(this.getClass());
      
      protected StatefulSessionContainer container;
  -     
  +   
      // Static -------------------------------------------------------
  -
  +   
      private static Method getEJBHome;
      private static Method getHandle;
      private static Method getPrimaryKey;
      private static Method isIdentical;
      private static Method remove;
      
  -   static 
  +   static
      {
  -      try 
  +      try
         {
            Class[] noArg = new Class[0];
            getEJBHome = EJBObject.class.getMethod("getEJBHome", noArg);
            getHandle = EJBObject.class.getMethod("getHandle", noArg);
            getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", noArg);
  -         isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] 
{EJBObject.class});
  +         isIdentical = EJBObject.class.getMethod("isIdentical", new Class[]
  +         {EJBObject.class});
            remove = EJBObject.class.getMethod("remove", noArg);
         }
  -      catch (Exception e) {
  +      catch (Exception e)
  +      {
            e.printStackTrace();
            throw new ExceptionInInitializerError(e);
         }
      }
  -     
  +   
      // Constructors -------------------------------------------------
  -     
  +   
      // Public -------------------------------------------------------
  -
  -   public void setContainer(Container container) 
  -   { 
  -      this.container = (StatefulSessionContainer)container; 
  +   
  +   public void setContainer(Container container)
  +   {
  +      this.container = (StatefulSessionContainer)container;
      }
  -     
  +   
      public  Container getContainer()
      {
         return container;
  @@ -106,20 +108,20 @@
         throws Exception
      {
         // Get context
  -             
  +      
         // get a new context from the pool (this is a home method call)
         EnterpriseContext ctx = container.getInstancePool().get();
  -             
  -             
  +      
  +      
         // set the context on the Invocation
         mi.setEnterpriseContext(ctx);
  -
  +      
         // It is a new context for sure so we can lock it
         ctx.lock();
  -
  +      
         // Set the current security information
         ctx.setPrincipal(SecurityAssociation.getPrincipal());
  -
  +      
         try
         {
            // Invoke through interceptors
  @@ -130,7 +132,7 @@
            {
               // Release the lock
               ctx.unlock();
  -
  +            
               // Still free? Not free if create() was called successfully
               if (ctx.getId() == null)
               {
  @@ -139,21 +141,23 @@
            }
         }
      }
  -
  +   
      protected void register(EnterpriseContext ctx, Transaction tx, BeanLock lock)
      {
         // Create a new synchronization
         InstanceSynchronization synch = new InstanceSynchronization(tx, ctx, lock);
  -             
  -      try {
  +      
  +      try
  +      {
            // OSH: An extra check to avoid warning.
            // Can go when we are sure that we no longer get
            // the JTA violation warning.
  -         if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
  -                             
  +         if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
  +         {
  +            
               return;
            }
  -
  +         
            // We want to be notified when the transaction commits
            try
            {
  @@ -166,27 +170,29 @@
               getContainer().getLockManager().removeLockRef(lock.getId());
               throw ex;
            }
  -
  +         
            // EJB 1.1, 6.5.3
            synch.afterBegin();
  -
  -      } catch (RollbackException e) {
  -
  -      } catch (Exception e) {
  -
  +         
  +      } catch (RollbackException e)
  +      {
  +         
  +      } catch (Exception e)
  +      {
  +         
            throw new EJBException(e);
  -
  +         
         }
      }
  -
  +   
      public Object invoke(Invocation mi)
  -      throws Exception
  +   throws Exception
      {
         InstanceCache cache = container.getInstanceCache();
         InstancePool pool = container.getInstancePool();
         Object methodID = mi.getId();
         EnterpriseContext ctx = null;
  -
  +      
         BeanLock lock = (BeanLock)container.getLockManager().getLock(methodID);
         try
         {
  @@ -198,36 +204,38 @@
               interceptor and handles of passivated sessions expect that they are
               restored with the correct security context since the handles
               not serialize the principal and credential information.
  -            */
  +             */
               SecurityAssociation.setPrincipal(mi.getPrincipal());
               SecurityAssociation.setCredential(mi.getCredential());
  -
  +            
               // Get context
               ctx = cache.get(methodID);
               // Associate it with the method invocation
               mi.setEnterpriseContext(ctx);
  -
  +            
               // BMT beans will lock and replace tx no matter what, CMT do work on 
transaction
  -            if (!((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx()) {
  -
  +            if (!((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx())
  +            {
  +               
                  // Do we have a running transaction with the context
                  if (ctx.getTransaction() != null &&
  -                   // And are we trying to enter with another transaction
  -                   !ctx.getTransaction().equals(mi.getTransaction()))
  +               // And are we trying to enter with another transaction
  +               !ctx.getTransaction().equals(mi.getTransaction()))
                  {
                     // Calls must be in the same transaction
                     throw new RemoteException("Application Error: tried to enter 
Stateful bean with different transaction context");
                  }
  -
  +               
                  //If the instance will participate in a new transaction we register 
a sync for it
  -               if (ctx.getTransaction() == null && mi.getTransaction() != null) {
  +               if (ctx.getTransaction() == null && mi.getTransaction() != null)
  +               {
                     register(ctx, mi.getTransaction(), lock);
                  }
               }
  -
  +            
               if (!ctx.isLocked())
               {
  -
  +               
                  //take it!
                  ctx.lock();
               }
  @@ -248,10 +256,10 @@
            {
               lock.releaseSync();
            }
  -
  +         
            // Set the current security information
            ctx.setPrincipal(mi.getPrincipal());
  -
  +         
            try
            {
               // Invoke through interceptors
  @@ -261,21 +269,21 @@
               // Discard instance
               cache.remove(methodID);
               ctx = null;
  -
  +            
               throw e;
            } catch (RuntimeException e)
            {
               // Discard instance
               cache.remove(methodID);
               ctx = null;
  -
  +            
               throw e;
            } catch (Error e)
            {
               // Discard instance
               cache.remove(methodID);
               ctx = null;
  -
  +            
               throw e;
            } finally
            {
  @@ -285,10 +293,10 @@
                  lock.sync(); // synchronized(ctx)
                  try
                  {
  -
  +                  
                     // release it
                     ctx.unlock();
  -
  +                  
                     // if removed, remove from cache
                     if (ctx.getId() == null)
                     {
  @@ -308,45 +316,45 @@
            container.getLockManager().removeLockRef(lock.getId());
         }
      }
  -
  +   
      protected boolean isCallAllowed(Invocation mi)
      {
         Method m = mi.getMethod();
         if (m.equals(getEJBHome) ||
  -          m.equals(getHandle) ||
  -          m.equals(getPrimaryKey) ||
  -          m.equals(isIdentical) ||
  -          m.equals(remove))
  +      m.equals(getHandle) ||
  +      m.equals(getPrimaryKey) ||
  +      m.equals(isIdentical) ||
  +      m.equals(remove))
         {
            return true;
         }
         return false;
      }
  -
  +   
      // Inner classes -------------------------------------------------
  -
  +   
      private class InstanceSynchronization
  -      implements Synchronization
  +   implements Synchronization
      {
         /**
          *  The transaction we follow.
          */
         private Transaction tx;
  -
  +      
         /**
          *  The context we manage.
          */
         private EnterpriseContext ctx;
  -
  +      
         // a utility boolean for session sync
         private boolean notifySession = false;
  -
  +      
         // Utility methods for the notifications
         private Method afterBegin;
         private Method beforeCompletion;
         private Method afterCompletion;
         private BeanLock lock;
  -
  +      
         /**
          *  Create a new instance synchronization instance.
          */
  @@ -356,65 +364,74 @@
            this.ctx = ctx;
            this.lock = lock;
            this.lock.addRef();
  -                     
  -         // Let's compute it now, to speed things up we could 
  +         
  +         // Let's compute it now, to speed things up we could
            notifySession = (ctx.getInstance() instanceof 
javax.ejb.SessionSynchronization);
  -                     
  -         if (notifySession) {
  -            try {
  +         
  +         if (notifySession)
  +         {
  +            try
  +            {
                  // Get the class we are working on
                  Class sync = Class.forName("javax.ejb.SessionSynchronization");
  -                                     
  +               
                  // Lookup the methods on it
                  afterBegin = sync.getMethod("afterBegin", new Class[0]);
                  beforeCompletion = sync.getMethod("beforeCompletion", new Class[0]);
  -               afterCompletion =  sync.getMethod("afterCompletion", new Class[] 
{boolean.class});
  +               afterCompletion =  sync.getMethod("afterCompletion", new Class[]
  +               {boolean.class});
               }
  -            catch (Exception e) {
  +            catch (Exception e)
  +            {
                  log.error("failed to setup InstanceSynchronization", e);
               }
            }
         }
  -             
  +      
         // Synchronization implementation -----------------------------
  -
  -      public void afterBegin() 
  +      
  +      public void afterBegin()
         {
  -         if (notifySession) 
  +         if (notifySession)
            {
  -            try 
  +            try
               {
                  afterBegin.invoke(ctx.getInstance(), new Object[0]);
               }
  -            catch (Exception e) 
  +            catch (Exception e)
               {
                  log.error("failed to invoke afterBegin", e);
               }
            }
         }
  -             
  +      
         public void beforeCompletion()
         {
  -         // DEBUG log.debug("beforeCompletion called");
  -                     
  +         if( log.isTraceEnabled() )
  +            log.trace("beforeCompletion called");
  +
            // lock the context the transaction is being commited (no need for sync)
            ctx.lock();
  -
  -         if (notifySession) {
  -            try {
  -                                     
  +         
  +         if (notifySession)
  +         {
  +            try
  +            {
  +               
                  beforeCompletion.invoke(ctx.getInstance(), new Object[0]);
               }
  -            catch (Exception e) {
  +            catch (Exception e)
  +            {
                  log.error("failed to invoke beforeCompletion", e);
               }
            }
         }
  -             
  +      
         public void afterCompletion(int status)
         {
  -         // DEBUG log.debug("afterCompletion called");
  -                     
  +         if( log.isTraceEnabled() )
  +            log.trace("afterCompletion called");
  +         
            lock.sync();
            try
            {
  @@ -424,23 +441,30 @@
               // unlock this context
               ctx.unlock();
               
  -            if (notifySession) {
  +            if (notifySession)
  +            {
                  
  -               try {
  +               try
  +               {
                     
  -                  if (status == Status.STATUS_COMMITTED) {
  +                  if (status == Status.STATUS_COMMITTED)
  +                  {
                        afterCompletion.invoke(ctx.getInstance(),
  -                                            new Object[] { Boolean.TRUE });
  +                     new Object[]
  +                     { Boolean.TRUE });
                     }
  -                  else {
  +                  else
  +                  {
                        afterCompletion.invoke(ctx.getInstance(),
  -                                            new Object[] { Boolean.FALSE });
  +                     new Object[]
  +                     { Boolean.FALSE });
                     }
                  }
  -               catch (Exception e) {
  +               catch (Exception e)
  +               {
                     log.error("failed to invoke afterCompletion", e);
                  }
  -            }                        
  +            }
            }
            finally
            {
  
  
  
  1.23      +275 -244  jboss/src/main/org/jboss/ejb/plugins/TxInterceptorCMT.java
  
  Index: TxInterceptorCMT.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptorCMT.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- TxInterceptorCMT.java     5 Jan 2002 12:08:50 -0000       1.22
  +++ TxInterceptorCMT.java     12 Feb 2002 08:15:36 -0000      1.23
  @@ -1,9 +1,9 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.ejb.plugins;
   
   import java.lang.reflect.Method;
  @@ -16,9 +16,6 @@
   import javax.transaction.TransactionRequiredException;
   
   import org.jboss.invocation.Invocation;
  -
  -// TODO this needs to be replaced with the log4j logging
  -
   import org.jboss.metadata.MetaData;
   import org.jboss.metadata.BeanMetaData;
   
  @@ -30,70 +27,72 @@
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Anatoly Akkerman</a>
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Ole Husgaard</a>
  - *  @version $Revision: 1.22 $
  + *  @version $Revision: 1.23 $
    */
   public class TxInterceptorCMT
  -    extends AbstractTxInterceptor
  +extends AbstractTxInterceptor
   {
  -
  -    // Attributes ----------------------------------------------------
  -
  -    /** A cache mapping methods to transaction attributes. */
  -    private HashMap methodTx = new HashMap();
  -
  -    // Static --------------------------------------------------------
  -
  -    // Constructors --------------------------------------------------
  -
  -    // Public --------------------------------------------------------
  -
  -    // Interceptor implementation --------------------------------------
  -
  -    public Object invokeHome(Invocation mi)
  -        throws Exception
  -    {
  -        return runWithTransactions(false, mi);
  -    }
  -
  -    /**
  -     *  This method does invocation interpositioning of tx management
  -     */
  -    public Object invoke(Invocation mi)
  -        throws Exception
  -    {
  -        return runWithTransactions(true, mi);
  -    }
  -
  -    // Private  ------------------------------------------------------
  -
  -    private void printMethod(Method m, byte type) {
  -        String name;
  -        switch(type) {
  -            case MetaData.TX_MANDATORY:
  -                name = "TX_MANDATORY";
  +   
  +   // Attributes ----------------------------------------------------
  +   
  +   /** A cache mapping methods to transaction attributes. */
  +   private HashMap methodTx = new HashMap();
  +   
  +   // Static --------------------------------------------------------
  +   
  +   // Constructors --------------------------------------------------
  +   
  +   // Public --------------------------------------------------------
  +   
  +   // Interceptor implementation --------------------------------------
  +   
  +   public Object invokeHome(Invocation mi)
  +   throws Exception
  +   {
  +      return runWithTransactions(false, mi);
  +   }
  +   
  +   /**
  +    *  This method does invocation interpositioning of tx management
  +    */
  +   public Object invoke(Invocation mi)
  +   throws Exception
  +   {
  +      return runWithTransactions(true, mi);
  +   }
  +   
  +   // Private  ------------------------------------------------------
  +   
  +   private void printMethod(Method m, byte type)
  +   {
  +      String name;
  +      switch(type)
  +      {
  +         case MetaData.TX_MANDATORY:
  +            name = "TX_MANDATORY";
               break;
  -            case MetaData.TX_NEVER:
  -                name = "TX_NEVER";
  +         case MetaData.TX_NEVER:
  +            name = "TX_NEVER";
               break;
  -            case MetaData.TX_NOT_SUPPORTED:
  -                name = "TX_NOT_SUPPORTED";
  +         case MetaData.TX_NOT_SUPPORTED:
  +            name = "TX_NOT_SUPPORTED";
               break;
  -            case MetaData.TX_REQUIRED:
  -                name = "TX_REQUIRED";
  +         case MetaData.TX_REQUIRED:
  +            name = "TX_REQUIRED";
               break;
  -            case MetaData.TX_REQUIRES_NEW:
  -                name = "TX_REQUIRES_NEW";
  +         case MetaData.TX_REQUIRES_NEW:
  +            name = "TX_REQUIRES_NEW";
               break;
  -            case MetaData.TX_SUPPORTS:
  -                name = "TX_SUPPORTS";
  +         case MetaData.TX_SUPPORTS:
  +            name = "TX_SUPPORTS";
               break;
  -            default:
  -                name = "TX_UNKNOWN";
  -        }
  -        if (log.isDebugEnabled())
  -           log.debug(name+" for "+m.getName());
  -    }
  -
  +         default:
  +            name = "TX_UNKNOWN";
  +      }
  +      if (log.isTraceEnabled())
  +         log.trace(name+" for "+m.getName());
  +   }
  +   
       /*
        *  This method does invocation interpositioning of tx management.
        *
  @@ -110,191 +109,223 @@
        *                          interface.
        *  @param mi The <code>Invocation</code> of this call.
        */
  -    private Object runWithTransactions(boolean remoteInvocation,
  -                                       Invocation mi)
  -        throws Exception
  -    {
  -        // Old transaction is the transaction that comes with the MI
  -        Transaction oldTransaction = mi.getTransaction();
  -        // New transaction is the new transaction this might start
  -        Transaction newTransaction = null;
  -
  -        //DEBUG log.debug("Current transaction in MI is " + oldTransaction);
  -
  -        byte transType = getTransactionMethod(mi.getMethod(), remoteInvocation);
  -     //DEBUG printMethod(mi.getMethod(), transType);
  -
  -        // Thread arriving must be clean (jboss doesn't set the thread
  -        // previously). However optimized calls come with associated
  -        // thread for example. We suspend the thread association here, and
  -        // resume in the finally block of the following try.
  -        Transaction threadTx = tm.suspend();
  -     //DEBUG log.debug("Thread came in with tx " + threadTx);
  -        try { // OSH FIXME: Indentation
  -
  -        switch (transType) {
  +   private Object runWithTransactions(boolean remoteInvocation,
  +      Invocation mi)
  +      throws Exception
  +   {
  +      // Old transaction is the transaction that comes with the MI
  +      Transaction oldTransaction = mi.getTransaction();
  +      // New transaction is the new transaction this might start
  +      Transaction newTransaction = null;
  +      
  +      boolean trace = log.isTraceEnabled();
  +      if( trace )
  +         log.trace("Current transaction in MI is " + oldTransaction);
  +      
  +      byte transType = getTransactionMethod(mi.getMethod(), remoteInvocation);
  +      if( trace )
  +         printMethod(mi.getMethod(), transType);
  +
  +      // Thread arriving must be clean (jboss doesn't set the thread
  +      // previously). However optimized calls come with associated
  +      // thread for example. We suspend the thread association here, and
  +      // resume in the finally block of the following try.
  +      Transaction threadTx = tm.suspend();
  +      if( trace )
  +         log.trace("Thread came in with tx " + threadTx);
  +      try
  +      {
  +         switch (transType)
  +         {
               case MetaData.TX_NOT_SUPPORTED:
  -                // Do not set a transaction on the thread even if in MI, just run
  -                return invokeNext(remoteInvocation, mi, false);
  -
  +               // Do not set a transaction on the thread even if in MI, just run
  +               return invokeNext(remoteInvocation, mi, false);
  +               
               case MetaData.TX_REQUIRED:
  -                if (oldTransaction == null) { // No tx running
  -                    // Create tx
  -                    tm.begin();
  -
  -                    // get the tx
  -                    newTransaction = tm.getTransaction();
  -                 //DEBUG log.debug("Starting new tx " + newTransaction);
  -
  -                    // Let the method invocation know
  -                    mi.setTransaction(newTransaction);
  -                } else { // We have a tx propagated
  -                    // Associate it with the thread
  -                    tm.resume(oldTransaction);
  -                }
  -
  -                // Continue invocation
  -                try {
  -                    return invokeNext(remoteInvocation, mi, newTransaction != null);
  -                } finally {
  -                    //DEBUG                log.debug("TxInterceptorCMT: In 
finally");
  -
  -                    // Only do something if we started the transaction
  -                    if (newTransaction != null) {
  -                        // Marked rollback
  -                        if (newTransaction.getStatus() == 
Status.STATUS_MARKED_ROLLBACK) {
  -                            newTransaction.rollback();
  -                        } else {
  -                            // Commit tx
  -                            // This will happen if
  -                            // a) everything goes well
  -                            // b) app. exception was thrown
  -                            //DEBUG log.debug("TxInterceptorCMT:before commit of " 
+ newTransaction);
  -                            newTransaction.commit();
  -                            //DEBUG log.debug("TxInterceptorCMT:after commit of " + 
newTransaction);
  -                        }
  -
  -                        // reassociate the oldTransaction with the Invocation (even 
null)
  -                        mi.setTransaction(oldTransaction);
  -                    }
  -                    // Always drop thread association even if committing or
  -                    // rolling back the newTransaction because not all TMs
  -                    // will drop thread associations when commit() or rollback()
  -                    // are called through tx itself (see JTA spec that seems to
  -                    // indicate that thread assoc is required to be dropped only
  -                    // when commit() and rollback() are called through 
TransactionManager
  -                    // interface)
  -                    tm.suspend();
  -                    
  -                }
  -
  +               if (oldTransaction == null)
  +               { // No tx running
  +                  // Create tx
  +                  tm.begin();
  +                  
  +                  // get the tx
  +                  newTransaction = tm.getTransaction();
  +                  if( trace )
  +                     log.trace("Starting new tx " + newTransaction);
  +                  
  +                  // Let the method invocation know
  +                  mi.setTransaction(newTransaction);
  +               }
  +               else
  +               { // We have a tx propagated
  +                  // Associate it with the thread
  +                  tm.resume(oldTransaction);
  +               }
  +
  +               // Continue invocation
  +               try
  +               {
  +                  return invokeNext(remoteInvocation, mi, newTransaction != null);
  +               }
  +               finally
  +               {
  +                  if( trace )
  +                     log.trace("TxInterceptorCMT: In finally");
  +
  +                  // Only do something if we started the transaction
  +                  if (newTransaction != null)
  +                  {
  +                     // Marked rollback
  +                     if (newTransaction.getStatus() == 
Status.STATUS_MARKED_ROLLBACK)
  +                     {
  +                        newTransaction.rollback();
  +                     }
  +                     else
  +                     {
  +                        // Commit tx
  +                        // This will happen if
  +                        // a) everything goes well
  +                        // b) app. exception was thrown
  +                        if( trace )
  +                           log.trace("TxInterceptorCMT:before commit of " + 
newTransaction);
  +                        newTransaction.commit();
  +                        if( trace )
  +                           log.trace("TxInterceptorCMT:after commit of " + 
newTransaction);
  +                     }
  +                     
  +                     // reassociate the oldTransaction with the Invocation (even 
null)
  +                     mi.setTransaction(oldTransaction);
  +                  }
  +                  // Always drop thread association even if committing or
  +                  // rolling back the newTransaction because not all TMs
  +                  // will drop thread associations when commit() or rollback()
  +                  // are called through tx itself (see JTA spec that seems to
  +                  // indicate that thread assoc is required to be dropped only
  +                  // when commit() and rollback() are called through 
TransactionManager
  +                  // interface)
  +                  tm.suspend();
  +                  
  +               }
  +               
               case MetaData.TX_SUPPORTS:
  -                {
  -                    // Associate old transaction with the thread
  -                    // Some TMs cannot resume a null transaction and will throw
  -                    // an exception (e.g. Tyrex), so make sure it is not null
  -                    if (oldTransaction != null)
  -                        tm.resume(oldTransaction);
  -
  -                    try {
  -                        return invokeNext(remoteInvocation, mi, false);
  -                    } finally {
  -                        tm.suspend();
  -                    }
  -
  -                    // Even on error we don't do anything with the tx, we didn't 
start it
  -                }
  -
  +            {
  +               // Associate old transaction with the thread
  +               // Some TMs cannot resume a null transaction and will throw
  +               // an exception (e.g. Tyrex), so make sure it is not null
  +               if (oldTransaction != null)
  +                  tm.resume(oldTransaction);
  +               
  +               try
  +               {
  +                  return invokeNext(remoteInvocation, mi, false);
  +               }
  +               finally
  +               {
  +                  tm.suspend();
  +               }
  +               
  +               // Even on error we don't do anything with the tx, we didn't start it
  +            }
  +            
               case MetaData.TX_REQUIRES_NEW:
  -                {
  -                    // Always begin a transaction
  -                    tm.begin();
  -
  -                    // get it
  -                    newTransaction = tm.getTransaction();
  -
  -                    // Set it on the method invocation
  -                    mi.setTransaction(newTransaction);
  -                    // Continue invocation
  -                    try {
  -                        return invokeNext(remoteInvocation, mi, true);
  -                    } finally {
  -                        // We started the transaction for sure so we commit or roll 
back
  -
  -                        if (newTransaction.getStatus() == 
Status.STATUS_MARKED_ROLLBACK) {
  -                            newTransaction.rollback();
  -                        } else {
  -                            // Commit tx
  -                            // This will happen if
  -                            // a) everything goes well
  -                            // b) app. exception was thrown
  -                            newTransaction.commit();
  -                        }
  -
  -                        // set the old transaction back on the method invocation
  -                        mi.setTransaction(oldTransaction);
  -                        tm.suspend();
  -                    }
  -                }
  +            {
  +               // Always begin a transaction
  +               tm.begin();
  +               
  +               // get it
  +               newTransaction = tm.getTransaction();
  +               
  +               // Set it on the method invocation
  +               mi.setTransaction(newTransaction);
  +               // Continue invocation
  +               try
  +               {
  +                  return invokeNext(remoteInvocation, mi, true);
  +               }
  +               finally
  +               {
  +                  // We started the transaction for sure so we commit or roll back
  +                  
  +                  if (newTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK)
  +                  {
  +                     newTransaction.rollback();
  +                  }
  +                  else
  +                  {
  +                     // Commit tx
  +                     // This will happen if
  +                     // a) everything goes well
  +                     // b) app. exception was thrown
  +                     newTransaction.commit();
  +                  }
  +                  
  +                  // set the old transaction back on the method invocation
  +                  mi.setTransaction(oldTransaction);
  +                  tm.suspend();
  +               }
  +            }
               case MetaData.TX_MANDATORY:
  -                if (oldTransaction == null) // no transaction = bad!
  -                    throw new TransactionRequiredException("Transaction Required, 
read the spec!");
  -                // Associate it with the thread
  -                tm.resume(oldTransaction);
  -                try {
  -                    return invokeNext(remoteInvocation, mi, false);
  -                } finally {
  -                    tm.suspend();
  -                }
  -
  +               if (oldTransaction == null) // no transaction = bad!
  +                  throw new TransactionRequiredException("Transaction Required, 
read the spec!");
  +               // Associate it with the thread
  +               tm.resume(oldTransaction);
  +               try
  +               {
  +                  return invokeNext(remoteInvocation, mi, false);
  +               } finally
  +               {
  +                  tm.suspend();
  +               }
  +               
               case MetaData.TX_NEVER:
  -                if (oldTransaction != null) // Transaction = bad!
  -                    throw new RemoteException("Transaction not allowed");
  -                return invokeNext(remoteInvocation, mi, false);
  -        }
  -
  -        } finally { // OSH FIXME: Indentation
  -            // IN case we had a Tx associated with the thread reassociate
  -            if (threadTx != null)
  -                tm.resume(threadTx);
  -        }
  -
  -        return null;
  -    }
  -
  -    // Protected  ----------------------------------------------------
  -
  -    // This should be cached, since this method is called very often
  -    protected byte getTransactionMethod(Method m, boolean remoteInvocation)
  -    {
  -        Byte b = (Byte)methodTx.get(m);
  -        if (b != null) return b.byteValue();
  -
  -        BeanMetaData bmd = container.getBeanMetaData();
  -
  -//DEBUG        log.debug("Found metadata for bean '"+bmd.getEjbName()+"'"+" method 
is "+m.getName());
  -
  -        byte result = bmd.getMethodTransactionType(m.getName(), 
m.getParameterTypes(), remoteInvocation);
  -
  -        // provide default if method is not found in descriptor
  -        if (result == MetaData.TX_UNKNOWN) result = MetaData.TX_REQUIRED;
  -
  -        methodTx.put(m, new Byte(result));
  -        return result;
  -    }
  -
  -    // Inner classes -------------------------------------------------
  -
  -  // Monitorable implementation ------------------------------------
  -  public void sample(Object s)
  -  {
  -    // Just here to because Monitorable request it but will be removed soon
  -  }
  -  public Map retrieveStatistic()
  -  {
  -    return null;
  -  }
  -  public void resetStatistic()
  -  {
  -  }
  +               if (oldTransaction != null) // Transaction = bad!
  +                  throw new RemoteException("Transaction not allowed");
  +               return invokeNext(remoteInvocation, mi, false);
  +         }
  +         
  +      }
  +      finally
  +      {
  +         // IN case we had a Tx associated with the thread reassociate
  +         if (threadTx != null)
  +            tm.resume(threadTx);
  +      }
  +
  +      return null;
  +   }
  +   
  +   // Protected  ----------------------------------------------------
  +   
  +   // This should be cached, since this method is called very often
  +   protected byte getTransactionMethod(Method m, boolean remoteInvocation)
  +   {
  +      Byte b = (Byte)methodTx.get(m);
  +      if (b != null) return b.byteValue();
  +      
  +      BeanMetaData bmd = container.getBeanMetaData();
  +      
  +      //DEBUG        log.debug("Found metadata for bean '"+bmd.getEjbName()+"'"+" 
method is "+m.getName());
  +      
  +      byte result = bmd.getMethodTransactionType(m.getName(), 
m.getParameterTypes(), remoteInvocation);
  +      
  +      // provide default if method is not found in descriptor
  +      if (result == MetaData.TX_UNKNOWN) result = MetaData.TX_REQUIRED;
  +      
  +      methodTx.put(m, new Byte(result));
  +      return result;
  +   }
  +   
  +   // Inner classes -------------------------------------------------
  +   
  +   // Monitorable implementation ------------------------------------
  +   public void sample(Object s)
  +   {
  +      // Just here to because Monitorable request it but will be removed soon
  +   }
  +   public Map retrieveStatistic()
  +   {
  +      return null;
  +   }
  +   public void resetStatistic()
  +   {
  +   }
   }
  
  
  

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

Reply via email to