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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 3 08:49:58 EDT 2007


Author: wolfc
Date: 2007-05-03 08:49:58 -0400 (Thu, 03 May 2007)
New Revision: 62780

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
Log:
EJBTHREE-953: throwing EJBException

Added: trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptor.java	2007-05-03 12:49:58 UTC (rev 62780)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.tx;
+
+import javax.ejb.EJBException;
+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.
+ * 
+ * EJB3 13.6.2.6
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class TxInterceptor extends org.jboss.aspects.tx.TxInterceptor
+{
+   public static class Never extends org.jboss.aspects.tx.TxInterceptor.Never
+   {
+      public Never(TransactionManager tm, TxPolicy policy)
+      {
+         super(tm, policy);
+      }
+      
+      @Override
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         if (tm.getTransaction() != null)
+         {
+            throw new EJBException("Transaction present on server in Never call (EJB3 13.6.2.6)");
+         }
+         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-05-03 12:43:24 UTC (rev 62779)
+++ trunk/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2007-05-03 12:49:58 UTC (rev 62780)
@@ -22,19 +22,17 @@
 package org.jboss.ejb3.tx;
 
 import java.lang.reflect.Method;
+
 import javax.ejb.TransactionAttribute;
 import javax.ejb.TransactionAttributeType;
 import javax.ejb.TransactionManagementType;
+
 import org.jboss.annotation.ejb.TransactionTimeout;
 import org.jboss.aop.Advisor;
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aop.joinpoint.MethodJoinpoint;
-import org.jboss.aspects.tx.TxInterceptor;
+import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionManagerLocator;
-import org.jboss.tm.TxManager;
-import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.ejb3.stateless.StatelessContainer;
 
 /**
  * This interceptor handles transactions for AOP
@@ -44,8 +42,8 @@
  */
 public class TxInterceptorFactory extends org.jboss.aspects.tx.TxInterceptorFactory
 {
-   private static final Logger log = Logger
-   .getLogger(TxInterceptorFactory.class);
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(TxInterceptorFactory.class);
 
    protected String resolveTxType(Advisor advisor, Joinpoint jp)
    {
@@ -115,8 +113,13 @@
          super.initialize();
 
       String txType = resolveTxType(advisor, jp).toUpperCase();
-      if (txType.equals("REQUIRED"))
+      if (txType.equals("NEVER"))
       {
+         // make sure we use the EJB3 interceptor, not the AOP one. 
+         return new TxInterceptor.Never(TxUtil.getTransactionManager(), policy);
+      }
+      else if (txType.equals("REQUIRED"))
+      {
          return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
       }
       else if (txType.equals("REQUIRESNEW"))
@@ -129,7 +132,6 @@
       }
    }
 
-
    public String getName()
    {
       return getClass().getName();




More information about the jboss-cvs-commits mailing list