[jboss-cvs] JBossAS SVN: r57365 - in branches/JBoss_4_0_4_GA_CP: aspects/src/main/org/jboss/aspects/tx ejb3/src/main/org/jboss/ejb3/entity ejb3/src/main/org/jboss/ejb3/tx server/src/main/org/jboss/jms/asf

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 2 14:17:56 EDT 2006


Author: kevin.conner at jboss.com
Date: 2006-10-02 14:17:47 -0400 (Mon, 02 Oct 2006)
New Revision: 57365

Added:
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
Modified:
   branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java
   branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
   branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
   branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
   branches/JBoss_4_0_4_GA_CP/server/src/main/org/jboss/jms/asf/StdServerSession.java
Log:
Updated TxManager references for ASPATCH-80

Added: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * When we don't know where we are
+ */
+class NullTransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      return 0;
+   }
+}
\ No newline at end of file


Property changes on: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.TransactionTimeoutConfiguration;
+
+/**
+ * For use with newer versions of JBoss supporting the TransactionTimeoutConfiguration interface
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+class TransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm) throws Exception
+   {
+      if (tm instanceof TransactionTimeoutConfiguration)
+      {
+         return ((TransactionTimeoutConfiguration)tm).getTransactionTimeout();
+      }
+      return 0;
+   }
+}
\ No newline at end of file


Property changes on: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxInterceptor.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -37,6 +37,7 @@
 public class TxInterceptor
 {
    private static final Logger log = Logger.getLogger(TxInterceptor.class);
+   private static final TxTimeoutReader txTimeoutReader = TxTimeoutReaderFactory.getTxTimeoutReader();
 
    public static class Never implements Interceptor
    {
@@ -174,20 +175,13 @@
 
       public Object invoke(Invocation invocation) throws Throwable
       {
-         org.jboss.tm.TxManager txManager = (org.jboss.tm.TxManager)tm;
-         int oldTimeout = 0;
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);
          
-         if (tm instanceof org.jboss.tm.TxManager)
-         {
-            txManager = (org.jboss.tm.TxManager)tm;
-            oldTimeout = txManager.getTransactionTimeout();
-         }
-         
          try 
          {
-            if (timeout != -1 && txManager != null)
+            if (timeout != -1 && tm != null)
             {
-               txManager.setTransactionTimeout(timeout);
+            	tm.setTransactionTimeout(timeout);
             }
                
             Transaction tx = tm.getTransaction();
@@ -203,9 +197,9 @@
          }
          finally
          {
-            if (txManager != null)
+            if (tm != null)
             {
-               txManager.setTransactionTimeout(oldTimeout);
+            	tm.setTransactionTimeout(oldTimeout);
             }
          }
       }
@@ -241,20 +235,13 @@
 
       public Object invoke(Invocation invocation) throws Throwable
       {
-         org.jboss.tm.TxManager txManager = (org.jboss.tm.TxManager)tm;
-         int oldTimeout = 0;
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);
          
-         if (tm instanceof org.jboss.tm.TxManager)
-         {
-            txManager = (org.jboss.tm.TxManager)tm;
-            oldTimeout = txManager.getTransactionTimeout();
-         }
-         
          try 
          {
-            if (timeout != -1 && txManager != null)
+            if (timeout != -1 && tm != null)
             {
-               txManager.setTransactionTimeout(timeout);
+            	tm.setTransactionTimeout(timeout);
             }
                
             Transaction tx = tm.getTransaction();
@@ -277,9 +264,9 @@
          }
          finally
          {
-            if (txManager != null)
+            if (tm != null)
             {
-               txManager.setTransactionTimeout(oldTimeout);
+            	tm.setTransactionTimeout(oldTimeout);
             }
          }
       }
@@ -317,6 +304,5 @@
          }
          return policy.invokeInCallerTx(invocation, tx);
       }
-
    }
 }

Added: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class TxManagerTimeOutReader implements TxTimeoutReader 
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      if (tm instanceof org.jboss.tm.TxManager)
+      {
+         return ((org.jboss.tm.TxManager)tm).getTransactionTimeout();
+      }
+      return 0;
+   }
+}
\ No newline at end of file


Property changes on: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public interface TxTimeoutReader
+{
+   int getTransactionTimeOut(TransactionManager tm) throws Exception;
+   
+}


Property changes on: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.aspects.tx;
+
+/**
+ * Obtains the correct mechanism to get hold of a transaction timeout.
+ * Newer versions of JBoss should use the TransactionTimeoutConfiguration interfsce.
+ * For older versions we need to access the TxManager directly
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class TxTimeoutReaderFactory
+{
+   public static TxTimeoutReader getTxTimeoutReader()
+   {
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TransactionTimeoutConfiguration");
+         return new TransactionTimeoutConfigurationReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TxManager");
+         return new TxManagerTimeOutReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+
+      return new NullTransactionTimeoutConfigurationReader();
+   }
+}


Property changes on: branches/JBoss_4_0_4_GA_CP/aspects/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -23,7 +23,6 @@
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContextType;
 import javax.persistence.TransactionRequiredException;
 import javax.transaction.RollbackException;
 import javax.transaction.Synchronization;
@@ -34,8 +33,8 @@
 import org.jboss.tm.TxManager;
 import org.jboss.tm.TxUtils;
 import org.jboss.ejb3.ThreadLocalStack;
+import org.jboss.ejb3.tx.TxUtil;
 
-import java.util.IdentityHashMap;
 import java.util.Map;
 
 /**
@@ -47,7 +46,7 @@
    private static final Logger log = Logger.getLogger(ManagedEntityManagerFactory.class);
 
    protected EntityManagerFactory entityManagerFactory;
-   protected TransactionLocal session = new TransactionLocal(TxManager.getInstance());
+   protected TransactionLocal session = new TransactionLocal(TxUtil.getTransactionManager());
    protected String kernelName;
 
    public static ThreadLocalStack<Map> nonTxStack = new ThreadLocalStack<Map>();

Modified: branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxInterceptorFactory.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -31,9 +31,7 @@
 import org.jboss.aop.joinpoint.MethodJoinpoint;
 import org.jboss.aspects.tx.TxInterceptor;
 import org.jboss.logging.Logger;
-import org.jboss.tm.TxManager;
 import org.jboss.ejb3.stateful.StatefulContainer;
-import org.jboss.ejb3.stateless.StatelessContainer;
 
 /**
  * This interceptor handles transactions for AOP
@@ -101,7 +99,7 @@
       // We have to do this until AOP supports matching based on annotation attributes
       TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);
       if (type == TransactionManagementType.BEAN)
-         return new BMTInterceptor(TxManager.getInstance(), !(advisor instanceof StatefulContainer));
+         return new BMTInterceptor(TxUtil.getTransactionManager(), !(advisor instanceof StatefulContainer));
 
       Method method = ((MethodJoinpoint) jp).getMethod();
       int timeout = resolveTransactionTimeout(advisor, method);
@@ -112,11 +110,11 @@
       String txType = resolveTxType(advisor, jp).toUpperCase();
       if (txType.equals("REQUIRED"))
       {
-         return new TxInterceptor.Required(TxManager.getInstance(), policy, timeout);
+         return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
       }
       else if (txType.equals("REQUIRESNEW"))
       {
-         return new TxInterceptor.RequiresNew(TxManager.getInstance(), policy, timeout);
+         return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
       }
       else
       {

Modified: branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/ejb3/src/main/org/jboss/ejb3/tx/TxUtil.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -23,9 +23,10 @@
 
 import javax.ejb.TransactionManagement;
 import javax.ejb.TransactionManagementType;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.transaction.TransactionManager;
 import org.jboss.aop.Advisor;
-import org.jboss.tm.TxManager;
 
 /**
  * Comment
@@ -35,9 +36,18 @@
  */
 public class TxUtil
 {
-   public static TransactionManager getTransactionManager()
+   public static TransactionManager getTransactionManager() throws RuntimeException
    {
-      return TxManager.getInstance();
+      try
+      {
+         InitialContext jndiContext = new InitialContext();
+         TransactionManager tm = (TransactionManager)jndiContext.lookup("java:TransactionManager");
+         return tm;
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException("Unable to lookup TransactionManager", e);
+      }
    }
 
    public static TransactionManagementType getTransactionManagementType(Advisor c)

Modified: branches/JBoss_4_0_4_GA_CP/server/src/main/org/jboss/jms/asf/StdServerSession.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/server/src/main/org/jboss/jms/asf/StdServerSession.java	2006-10-02 18:13:07 UTC (rev 57364)
+++ branches/JBoss_4_0_4_GA_CP/server/src/main/org/jboss/jms/asf/StdServerSession.java	2006-10-02 18:17:47 UTC (rev 57365)
@@ -357,6 +357,21 @@
                      session.commit();
                   }
                }
+               else
+               {
+                  if (trace)
+                     log.trace(StdServerSession.this + " transaction already ended tx=" + trans);
+                  // spend the thread association
+                  tm.suspend();
+
+                  // NO XASession? then manually rollback.
+                  // This is not so good but
+                  // it's the best we can do if we have no XASession.
+                  if (xaSession == null && serverSessionPool.isTransacted())
+                  {
+                     session.rollback();
+                  }
+               }
             }
          }
          catch (Exception e)




More information about the jboss-cvs-commits mailing list