[exo-jcr-commits] exo-jcr SVN: r1633 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 2 04:50:16 EST 2010


Author: nfilotto
Date: 2010-02-02 04:50:16 -0500 (Tue, 02 Feb 2010)
New Revision: 1633

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
Log:
EXOJCR-465: tm.setTransactionTimeout has to be called before tm.begin, a TL has been added to remind the application that a Transaction Timeout has already been set

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java	2010-02-02 08:18:34 UTC (rev 1632)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/transaction/jbosscache/GenericTransactionService.java	2010-02-02 09:50:16 UTC (rev 1633)
@@ -19,6 +19,8 @@
 package org.exoplatform.services.transaction.jbosscache;
 
 import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
 import org.exoplatform.services.transaction.ExoResource;
 import org.exoplatform.services.transaction.TransactionService;
 import org.jboss.cache.transaction.TransactionManagerLookup;
@@ -41,8 +43,12 @@
  */
 public class GenericTransactionService implements TransactionService
 {
-
    /**
+    * The logger 
+    */
+   private static final Log LOG = ExoLogger.getLogger(GenericTransactionService.class);
+   
+   /**
     * The default value of a transaction timeout in seconds
     */
    private static final int DEFAULT_TIME_OUT = 60;
@@ -230,6 +236,11 @@
        * The default timeout of the {@link Transaction}
        */
       private final int defaultTimeout;
+      
+      /**
+       * This is used to know if a timeout has already been set for the next transaction
+       */
+      private final ThreadLocal<Boolean> timeoutHasBeenSet = new ThreadLocal<Boolean>();
 
       public TransactionManagerTxTimeoutAware(TransactionManager tm, int defaultTimeout)
       {
@@ -242,9 +253,25 @@
        */
       public void begin() throws NotSupportedException, SystemException
       {
+         if (timeoutHasBeenSet.get() != null)
+         {
+            // clean the ThreadLocal
+            timeoutHasBeenSet.set(null);
+         }
+         else
+         {
+            try
+            {
+               // Set the default transaction timeout
+               tm.setTransactionTimeout(defaultTimeout);
+            }
+            catch (Exception e)
+            {
+               LOG.warn("Cannot set the transaction timeout", e);
+            }            
+         }
+         // Start the transaction
          tm.begin();
-         // Set the default transaction timeout
-         tm.setTransactionTimeout(defaultTimeout);
       }
 
       /**
@@ -302,6 +329,7 @@
       public void setTransactionTimeout(int timeout) throws SystemException
       {
          tm.setTransactionTimeout(timeout);
+         timeoutHasBeenSet.set(true);
       }
 
       /**



More information about the exo-jcr-commits mailing list