[jboss-cvs] JBossAS SVN: r70285 - projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Mar 1 16:27:43 EST 2008


Author: bdecoste
Date: 2008-03-01 16:27:43 -0500 (Sat, 01 Mar 2008)
New Revision: 70285

Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java
Log:
fixed @TransactionAttribute handling

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java	2008-03-01 10:06:57 UTC (rev 70284)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptor.java	2008-03-01 21:27:43 UTC (rev 70285)
@@ -26,8 +26,10 @@
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
+import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aspects.tx.TxPolicy;
+import org.jboss.logging.Logger;
 
 /**
  * Ensure the correct exceptions are thrown based on both caller
@@ -42,6 +44,8 @@
  */
 public class TxInterceptor extends org.jboss.aspects.tx.TxInterceptor
 {
+   private static final Logger log = Logger.getLogger(TxInterceptor.class);
+   
    public static class Never extends org.jboss.aspects.tx.TxInterceptor.Never
    {
       public Never(TransactionManager tm, TxPolicy policy)
@@ -111,4 +115,34 @@
          }
       }
    }
+
+   public static class Mandatory extends org.jboss.aspects.tx.TxInterceptor.Mandatory
+   {
+      public Mandatory(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public Mandatory(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         super(tm, policy, timeout);
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         Transaction tx = tm.getTransaction();
+         log.info("!!!!!!!!! invoke " + ((MethodInvocation)invocation).getMethod() + " " + tx);
+         if (tx == null)
+         {
+            policy.throwMandatory(invocation);
+         }
+         return policy.invokeInCallerTx(invocation, tx);
+      }
+
+   }
 }

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java	2008-03-01 10:06:57 UTC (rev 70284)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/tx/TxInterceptorFactory.java	2008-03-01 21:27:43 UTC (rev 70285)
@@ -44,16 +44,8 @@
 {
    @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)
+   protected TransactionAttributeType getTxType(Advisor advisor, Joinpoint jp)
    {
       Method method = ((MethodJoinpoint) jp).getMethod();
       TransactionAttribute tx = (TransactionAttribute) advisor.resolveAnnotation(method, TransactionAttribute.class);
@@ -61,27 +53,10 @@
       if (tx == null)
          tx = (TransactionAttribute) advisor.resolveAnnotation(TransactionAttribute.class);
 
-      String value = TxInterceptorFactory.TX_TYPE_REQUIRED;
-      if (tx != null)
+      TransactionAttributeType value = TransactionAttributeType.REQUIRED;
+      if (tx != null && tx.value() != null)
       {
-         TransactionAttributeType type = tx.value();
-
-         if (type == null)
-         {
-            value = TxInterceptorFactory.TX_TYPE_REQUIRED;
-         }
-         else if (type == TransactionAttributeType.NOT_SUPPORTED)
-         {
-            value = TxInterceptorFactory.TX_TYPE_NOT_SUPPORTED;
-         }
-         else if (type == TransactionAttributeType.REQUIRES_NEW)
-         {
-            value = TxInterceptorFactory.TX_TYPE_REQUIRES_NEW;
-         }
-         else
-         {
-            value = type.name();
-         }
+         value = tx.value();
       }
 
       return value;
@@ -120,24 +95,29 @@
       if (policy == null);
          super.initialize();
 
-      String txType = resolveTxType(advisor, jp).toUpperCase();
-      if (txType.equals(TxInterceptorFactory.TX_TYPE_NEVER))
+      TransactionAttributeType txType = getTxType(advisor, jp);
+      log.info("!!! createPerJoinpoint " + txType + " " + jp);
+      if (txType.equals(TransactionAttributeType.NEVER))
       {
          // make sure we use the EJB3 interceptor, not the AOP one. 
          return new TxInterceptor.Never(TxUtil.getTransactionManager(), policy);
       }
-      else if (txType.equals(TxInterceptorFactory.TX_TYPE_REQUIRED))
+      else if (txType.equals(TransactionAttributeType.REQUIRED))
       {
          return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
       }
-      else if (txType.equals(TxInterceptorFactory.TX_TYPE_REQUIRES_NEW))
+      else if (txType.equals(TransactionAttributeType.REQUIRES_NEW))
       {
          return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
       }
-      else if(txType.equals(TxInterceptorFactory.TX_TYPE_NOT_SUPPORTED))
+      else if(txType.equals(TransactionAttributeType.NOT_SUPPORTED))
       {
          return new TxInterceptor.NotSupported(TxUtil.getTransactionManager(), policy, timeout);
       }
+      else if(txType.equals(TransactionAttributeType.MANDATORY))
+      {
+         return new TxInterceptor.Mandatory(TxUtil.getTransactionManager(), policy, timeout);
+      }
       else
       {
          return super.createPerJoinpoint(advisor, jp);




More information about the jboss-cvs-commits mailing list