[Mulgara-svn] r1349 - trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi

ronald at mulgara.org ronald at mulgara.org
Thu Oct 23 13:11:48 UTC 2008


Author: ronald
Date: 2008-10-23 06:11:47 -0700 (Thu, 23 Oct 2008)
New Revision: 1349

Modified:
   trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java
Log:
Factored out exception handling for start() and end(), and fixed handling to
only remove transaction if the exception warrants it.

Modified: trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java	2008-10-23 13:11:42 UTC (rev 1348)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java	2008-10-23 13:11:47 UTC (rev 1349)
@@ -139,8 +139,7 @@
       doStart(tx, flags, isNew);
     } catch (Throwable t) {
       logger.warn("Failed to do start", t);
-      resourceManager.transactions.remove(new XidWrapper(xid));
-      throw new XAException(XAException.XAER_RMFAIL);
+      reThrow(t, tx, false);
     }
   }
 
@@ -155,8 +154,7 @@
       doEnd(tx, flags);
     } catch (Throwable t) {
       logger.warn("Failed to do end", t);
-      resourceManager.transactions.remove(new XidWrapper(xid));
-      throw new XAException(XAException.XAER_RMFAIL);
+      reThrow(t, tx, false);
     }
   }
 
@@ -322,6 +320,28 @@
     throw new XAException(XAException.XAER_NOTA);
   }
 
+  /**
+   * Rethrow the caught exception. If it is not an <var>XAException</var> then it is wrapped in an
+   * XAException. This method never returns normally.
+   *
+   * @param t         the exception to rethrow.
+   * @param tx        the current transaction
+   * @param doneOnRb  whether this transaction should be considered completed if <var>t</var>
+   *                  indicates a rollback.
+   * @throws XAException always
+   */
+  protected void reThrow(Throwable t, T tx, boolean doneOnRb) throws XAException {
+    if (t instanceof XAException) {
+      XAException xae = (XAException)t;
+      if (xae.errorCode == XAException.XAER_RMFAIL || doneOnRb && isRollback(xae)) {
+        resourceManager.transactions.remove(new XidWrapper(tx.xid));
+      }
+      throw xae;
+    }
+
+    throw (XAException)new XAException(XAException.XAER_RMERR).initCause(t);
+  }
+
   /** 
    * Invoked on start with valid flags and tx state.
    * 




More information about the Mulgara-svn mailing list