[jboss-cvs] JBossAS SVN: r67320 - trunk/ejb3/src/main/org/jboss/ejb3/tx.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 21 01:35:26 EST 2007


Author: ALRubinger
Date: 2007-11-21 01:35:26 -0500 (Wed, 21 Nov 2007)
New Revision: 67320

Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java
   trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
Log:
[EJBTHREE-1082] Redirected TransactionAttributeType NOT_SUPPORTED to use EJB3 Tx Interceptor instead of AOP-based one.  Overrides for "invoke" wrap Exceptions from Transactional Context within NOT_SUPPORTED as EJBException unless Exception thrown is @ApplicationException

Modified: trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java	2007-11-21 06:14:03 UTC (rev 67319)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java	2007-11-21 06:35:26 UTC (rev 67320)
@@ -21,19 +21,23 @@
  */
 package org.jboss.ejb3.tx;
 
+import javax.ejb.ApplicationException;
 import javax.ejb.EJBException;
+import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aspects.tx.TxPolicy;
 
 /**
- * Make sure we throw the right exception when transaction attribute never
- * is used.
+ * Ensure the correct exceptions are thrown based on both caller
+ * transactional context and supported Transaction Attribute Type
  * 
  * EJB3 13.6.2.6
+ * EJB3 Core Specification 14.3.1 Table 14
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:andrew.rubinger at redhat.com">ALR</a>
  * @version $Revision: $
  */
 public class TxInterceptor extends org.jboss.aspects.tx.TxInterceptor
@@ -55,4 +59,56 @@
          return policy.invokeInNoTx(invocation);
       }
    }
+   
+   public static class NotSupported extends org.jboss.aspects.tx.TxInterceptor.NotSupported
+   {
+      public NotSupported(TransactionManager tm, TxPolicy policy)
+      {
+         super(tm, policy);
+      }
+      
+      public NotSupported(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         super(tm, policy, timeout);
+      }
+
+      /**
+       * EJBTHREE-1082
+       * EJB3 Core Specification 14.3.1 Table 14
+       */
+      @Override
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         Transaction tx = tm.getTransaction();
+         if (tx != null)
+         {
+            tm.suspend();
+            try
+            {
+               return policy.invokeInNoTx(invocation);
+            }
+            catch (Exception e)
+            {
+               // If application exception was thrown, rethrow
+               if (e.getClass().getAnnotation(ApplicationException.class) != null)
+               {
+                  throw e;
+               }
+               // Otherwise wrap in EJBException
+               else
+               {
+                  throw new EJBException(e);
+               }
+            }
+            finally
+            {
+               tm.resume(tx);
+            }
+         }
+         else
+         {
+            return policy.invokeInNoTx(invocation);
+         }
+      }
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2007-11-21 06:14:03 UTC (rev 67319)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2007-11-21 06:35:26 UTC (rev 67320)
@@ -44,6 +44,14 @@
 {
    @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(TxInterceptorFactory.class);
+   
+   private static final String TX_TYPE_REQUIRED = "REQUIRED";
+   
+   private static final String TX_TYPE_NOT_SUPPORTED = "NOTSUPPORTED";
+   
+   private static final String TX_TYPE_REQUIRES_NEW = "REQUIRESNEW";
+   
+   private static final String TX_TYPE_NEVER = "NEVER";
 
    protected String resolveTxType(Advisor advisor, Joinpoint jp)
    {
@@ -53,22 +61,22 @@
       if (tx == null)
          tx = (TransactionAttribute) advisor.resolveAnnotation(TransactionAttribute.class);
 
-      String value = "REQUIRED";
+      String value = TxInterceptorFactory.TX_TYPE_REQUIRED;
       if (tx != null)
       {
          TransactionAttributeType type = tx.value();
 
          if (type == null)
          {
-            value = "REQUIRED";
+            value = TxInterceptorFactory.TX_TYPE_REQUIRED;
          }
          else if (type == TransactionAttributeType.NOT_SUPPORTED)
          {
-            value = "NOTSUPPORTED";
+            value = TxInterceptorFactory.TX_TYPE_NOT_SUPPORTED;
          }
          else if (type == TransactionAttributeType.REQUIRES_NEW)
          {
-            value = "REQUIRESNEW";
+            value = TxInterceptorFactory.TX_TYPE_REQUIRES_NEW;
          }
          else
          {
@@ -113,19 +121,23 @@
          super.initialize();
 
       String txType = resolveTxType(advisor, jp).toUpperCase();
-      if (txType.equals("NEVER"))
+      if (txType.equals(TxInterceptorFactory.TX_TYPE_NEVER))
       {
          // make sure we use the EJB3 interceptor, not the AOP one. 
          return new TxInterceptor.Never(TxUtil.getTransactionManager(), policy);
       }
-      else if (txType.equals("REQUIRED"))
+      else if (txType.equals(TxInterceptorFactory.TX_TYPE_REQUIRED))
       {
          return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
       }
-      else if (txType.equals("REQUIRESNEW"))
+      else if (txType.equals(TxInterceptorFactory.TX_TYPE_REQUIRES_NEW))
       {
          return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
       }
+      else if(txType.equals(TxInterceptorFactory.TX_TYPE_NOT_SUPPORTED))
+      {
+         return new TxInterceptor.NotSupported(TxUtil.getTransactionManager(), policy, timeout);
+      }
       else
       {
          return super.createPerJoinpoint(advisor, jp);




More information about the jboss-cvs-commits mailing list