[exo-jcr-commits] exo-jcr SVN: r1451 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Jan 17 08:17:53 EST 2010


Author: pnedonosko
Date: 2010-01-17 08:17:52 -0500 (Sun, 17 Jan 2010)
New Revision: 1451

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ReadOnlyWorkspaceException.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TxIsolatedOperation.java
Log:
EXOJCR-405 isolated operation errors handling rework

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java	2010-01-17 12:13:44 UTC (rev 1450)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java	2010-01-17 13:17:52 UTC (rev 1451)
@@ -291,7 +291,8 @@
       }
 
       @Override
-      protected void txAction() throws RepositoryException
+      protected void txAction() throws RepositoryException, NotSupportedException, SystemException, SecurityException,
+         IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
       {
          super.txAction();
 

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ReadOnlyWorkspaceException.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ReadOnlyWorkspaceException.java	2010-01-17 12:13:44 UTC (rev 1450)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ReadOnlyWorkspaceException.java	2010-01-17 13:17:52 UTC (rev 1451)
@@ -38,7 +38,7 @@
       super(message);
    }
    
-   public ReadOnlyWorkspaceException(ReadOnlyWorkspaceException e)
+   public ReadOnlyWorkspaceException(Throwable e)
    {
       super(e);
    }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TxIsolatedOperation.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TxIsolatedOperation.java	2010-01-17 12:13:44 UTC (rev 1450)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TxIsolatedOperation.java	2010-01-17 13:17:52 UTC (rev 1451)
@@ -12,13 +12,12 @@
 import javax.transaction.InvalidTransactionException;
 import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
-import javax.transaction.Status;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
 /**
- * Handles XA transactionalyisolated operation. I.e. Action of this operation will be executed in dedicated global transaction.
+ * Handles XA transactionaly isolated operation. I.e. Action of this operation will be executed in dedicated global transaction.
  * If another current transaction exists, the one will be suspended and resumed after the execution.
  * At other hand if nested isolated operations perform they will use same (current, active) transaction. 
  */
@@ -60,15 +59,26 @@
 
    /**
     * Apply action in new XA transaction (begin then commit or rollback). 
-    * Action will runs in dedicated (isolated) XA transaction, i.e. only JCR storage stuff will be involved to.
+    * Action will runs in dedicated XA transaction, i.e. only JCR storage stuff will be involved to.
     * But if it's a nested isolated operation it will run the action assuming the same (current, active) transaction.
+    * 
+    * @throws SystemException if XA unexpected error
+    * @throws NotSupportedException if unsupported XA operation
+    * @throws HeuristicRollbackException if all relevant updates have been rolled back on commit
+    * @throws HeuristicMixedException if some relevant updates have been committed and others have been rolled back on commit
+    * @throws RollbackException rollback error
+    * @throws IllegalStateException if thread is not associated with a transaction
+    * @throws SecurityException if thread is not allowed to commit the transaction
     */
-   protected void txAction() throws RepositoryException
+   protected void txAction() throws RepositoryException, NotSupportedException, SystemException, SecurityException,
+      IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
    {
       final boolean actInTx = currentIsolated.get() == null;
-      try
+      if (actInTx)
       {
-         if (actInTx)
+         // it's rooted isolated operation
+         boolean rollback = true;
+         try
          {
             beginTx();
 
@@ -78,81 +88,43 @@
             {
                currentIsolated.set(current);
             }
-         }
 
-         action();
+            action();
 
-         if (actInTx)
-         {
             commitTx();
-
-            // remove current isolated transaction from this thread
-            currentIsolated.remove();
+            rollback = false;
          }
-      }
-      catch (RollbackException e)
-      {
-         if (actInTx)
+         finally
          {
+            if (rollback)
+            {
+               doRollback();
+            }
+
             // remove current isolated transaction from this thread
             currentIsolated.remove();
          }
-         // Indicate that the transaction has been rolled back rather than committed.
-         throw new RepositoryException(e);
       }
-      catch (JCRInvalidItemStateException e)
+      else
       {
-         doRollback(actInTx);
-         throw new JCRInvalidItemStateException(e.getMessage(), e.getIdentifier(), e.getState(), e);
+         // it's nested isolated operation
+         action();
       }
-      catch (InvalidItemStateException e)
-      {
-         doRollback(actInTx);
-         throw new InvalidItemStateException(e);
-      }
-      catch (ItemExistsException e)
-      {
-         doRollback(actInTx);
-         throw new ItemExistsException(e);
-      }
-      catch (ReadOnlyWorkspaceException e)
-      {
-         doRollback(actInTx);
-         throw new ReadOnlyWorkspaceException(e);
-      }
-      catch (RepositoryException e)
-      {
-         doRollback(actInTx);
-         throw new RepositoryException(e);
-      }
-      catch (Exception e)
-      {
-         doRollback(actInTx);
-         throw new RepositoryException(e);
-      }
    }
 
    /**
-    * Performs rollback of the action if it's acts in original isolated transaction.
-    * If it's acts as a nested operation, the actions will be commited in original (rooted) isolated trnsaction.
-    *
-    * @param actInTx boolean, true if it's original isolated transaction
+    * Performs rollback of the action.
     */
-   private void doRollback(boolean actInTx)
+   private void doRollback()
    {
-      if (actInTx)
+      try
       {
-         try
-         {
-            rollbackTx();
-         }
-         catch (Exception e1)
-         {
-            LOG.error("Rollback error ", e1);
-         }
-         // remove current isolated transaction from this thread
-         currentIsolated.remove();
+         rollbackTx();
       }
+      catch (Exception e1)
+      {
+         LOG.error("Rollback error ", e1);
+      }
    }
 
    /**
@@ -167,14 +139,41 @@
          // suspend current ransaction and create one new for the JCR storage (cache etc.)
          // after the new transaction done we'll resume the current.
 
-         // TODO if nested in storage, e.g. save causes read, use one tx, e.g. via ThreadLocal 
-         //if (txManager.getStatus() == Status.STATUS_ACTIVE)
-
          Transaction current = txManager.suspend();
+         Throwable actionError = null; // used for resume errors handling
          try
          {
             txAction();
          }
+         catch (RollbackException e)
+         {
+            // Indicate that the transaction has been rolled back rather than committed.
+            throw new RepositoryException(actionError = e);
+         }
+         catch (JCRInvalidItemStateException e)
+         {
+            throw new JCRInvalidItemStateException(e.getMessage(), e.getIdentifier(), e.getState(), actionError = e);
+         }
+         catch (InvalidItemStateException e)
+         {
+            throw new InvalidItemStateException(actionError = e);
+         }
+         catch (ItemExistsException e)
+         {
+            throw new ItemExistsException(actionError = e);
+         }
+         catch (ReadOnlyWorkspaceException e)
+         {
+            throw new ReadOnlyWorkspaceException(actionError = e);
+         }
+         catch (RepositoryException e)
+         {
+            throw new RepositoryException(actionError = e);
+         }
+         catch (Throwable e)
+         {
+            throw new RepositoryException(actionError = e);
+         }
          finally
          {
             if (current != null)
@@ -185,18 +184,43 @@
                }
                catch (InvalidTransactionException e)
                {
-                  throw new RepositoryException(e);
+                  if (actionError == null)
+                  {
+                     throw new RepositoryException("Error of Transaction resume", e);
+                  }
+                  else
+                  {
+                     LOG.error("Error of Transaction resume", e);
+                  }
                }
                catch (IllegalStateException e)
                {
-                  throw new RepositoryException(e);
+                  if (actionError == null)
+                  {
+                     throw new RepositoryException("Error of Transaction resume", e);
+                  }
+                  else
+                  {
+                     LOG.error("Error of Transaction resume", e);
+                  }
                }
+               catch (SystemException e)
+               {
+                  if (actionError == null)
+                  {
+                     throw new RepositoryException("Error of Transaction resume", e);
+                  }
+                  else
+                  {
+                     LOG.error("Error of Transaction resume", e);
+                  }
+               }
             }
          }
       }
       catch (SystemException e)
       {
-         throw new RepositoryException(e);
+         throw new RepositoryException("Error of Transaction suspend", e);
       }
 
       // TODO to do not commit in curr thread (i.e. curr tx)



More information about the exo-jcr-commits mailing list