[Mulgara-svn] r648 - branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver

ronald at mulgara.org ronald at mulgara.org
Mon Feb 18 13:58:52 UTC 2008


Author: ronald
Date: 2008-02-18 05:58:52 -0800 (Mon, 18 Feb 2008)
New Revision: 648

Modified:
   branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
Log:
Only invoke getXAResource() in the resolvers once (per transaction) and re-use
the returned instance for prepare, commit, and rollback. This should help with
buggy XAResource implementations that don't follow the JTA spec (in particular
the first paragraph of section 3.4.6).


Modified: branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java
===================================================================
--- branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java	2008-02-18 13:44:00 UTC (rev 647)
+++ branches/mgr-73/src/jar/resolver/java/org/mulgara/resolver/MulgaraExternalTransaction.java	2008-02-18 13:58:52 UTC (rev 648)
@@ -60,6 +60,8 @@
   private Set<EnlistableResource> committed;
   private Set<EnlistableResource> rollbacked;
 
+  private Map<EnlistableResource, XAResource> xaResources;
+
   private MulgaraExternalTransactionFactory factory;
   private DatabaseOperationContext context;
 
@@ -78,6 +80,8 @@
     this.committed = new HashSet<EnlistableResource>();
     this.rollbacked = new HashSet<EnlistableResource>();
 
+    this.xaResources = new HashMap<EnlistableResource, XAResource>();
+
     this.hRollback = false;
     this.heurCode = 0;
     this.rollback = false;
@@ -165,11 +169,12 @@
     try {
       XAResource res = enlistable.getXAResource();
       for (EnlistableResource eres : enlisted) {
-        if (res.isSameRM(eres.getXAResource())) {
+        if (res.isSameRM(xaResources.get(eres))) {
           return;
         }
       }
       enlisted.add(enlistable);
+      xaResources.put(enlistable, res);
       // FIXME: We need to handle this uptodate operation properly - handle
       // suspension or mid-prepare/commit.
       // bringUptodate(res);
@@ -187,7 +192,7 @@
     report("commit");
     // FIXME: Consider the possiblity prepare failed, or was incomplete.
     for (EnlistableResource er : prepared) {
-      er.getXAResource().commit(xid, false);
+      xaResources.get(er).commit(xid, false);
       committed.add(er);
     }
     cleanupTransaction();
@@ -212,7 +217,7 @@
   void prepare(Xid xid) throws XAException {
     report("prepare");
     for (EnlistableResource er : enlisted) {
-      er.getXAResource().prepare(xid);
+      xaResources.get(er).prepare(xid);
       prepared.add(er);
     }
     // status = PREPARED; ?
@@ -231,7 +236,7 @@
       for (EnlistableResource er : enlisted) {
         try {
           if (!committed.contains(er)) {
-            er.getXAResource().rollback(xid);
+            xaResources.get(er).rollback(xid);
             rollbacked.add(er);
           }
         } catch (XAException ex) {




More information about the Mulgara-svn mailing list