[Mulgara-svn] r1346 - trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi
ronald at mulgara.org
ronald at mulgara.org
Thu Oct 23 13:11:29 UTC 2008
Author: ronald
Date: 2008-10-23 06:11:28 -0700 (Thu, 23 Oct 2008)
New Revision: 1346
Modified:
trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java
Log:
Factored out common transaction-lookup code.
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:22 UTC (rev 1345)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/AbstractXAResource.java 2008-10-23 13:11:28 UTC (rev 1346)
@@ -149,11 +149,7 @@
logger.debug("End xid=" + formatXid(xid) + " flags=" + formatFlags(flags));
}
- T tx = resourceManager.transactions.get(new XidWrapper(xid));
- if (tx == null) {
- logger.error("Attempting to end unknown transaction.");
- throw new XAException(XAException.XAER_NOTA);
- }
+ T tx = getTxn(xid, "end");
try {
doEnd(tx, flags);
@@ -169,11 +165,7 @@
logger.debug("Prepare xid=" + formatXid(xid));
}
- T tx = resourceManager.transactions.get(new XidWrapper(xid));
- if (tx == null) {
- logger.error("Attempting to prepare unknown transaction.");
- throw new XAException(XAException.XAER_NOTA);
- }
+ T tx = getTxn(xid, "prepare");
if (tx.rollback) {
logger.info("Attempting to prepare in failed transaction");
@@ -198,11 +190,8 @@
logger.debug("Commit xid=" + formatXid(xid) + " onePhase=" + onePhase);
}
- T tx = resourceManager.transactions.get(new XidWrapper(xid));
- if (tx == null) {
- logger.error("Attempting to commit unknown transaction.");
- throw new XAException(XAException.XAER_NOTA);
- }
+ T tx = getTxn(xid, "commit");
+
if (tx.rollback) {
logger.error("Attempting to commit in failed transaction");
rollback(xid);
@@ -249,11 +238,7 @@
logger.debug("Rollback xid=" + formatXid(xid));
}
- T tx = resourceManager.transactions.get(new XidWrapper(xid));
- if (tx == null) {
- logger.error("Attempting to rollback unknown transaction.");
- throw new XAException(XAException.XAER_NOTA);
- }
+ T tx = getTxn(xid, "roll back");
boolean clean = true;
try {
@@ -281,11 +266,7 @@
logger.debug("Forget xid=" + formatXid(xid));
}
- T tx = resourceManager.transactions.get(new XidWrapper(xid));
- if (tx == null) {
- logger.error("Attempting to forget unknown transaction.");
- throw new XAException(XAException.XAER_NOTA);
- }
+ T tx = getTxn(xid, "forget");
boolean clean = true;
try {
@@ -325,6 +306,22 @@
return same;
}
+ /**
+ * Look up the transaction-info object.
+ *
+ * @param xid the xid
+ * @param op the current operation - used for error messages
+ * @return the transaction-info object
+ * @throws XAException if no transaction-info could be found for the given xid
+ */
+ protected T getTxn(Xid xid, String op) throws XAException {
+ T tx = resourceManager.transactions.get(new XidWrapper(xid));
+ if (tx != null) return tx;
+
+ logger.error("Attempting to " + op + " unknown transaction: xid=" + formatXid(xid));
+ throw new XAException(XAException.XAER_NOTA);
+ }
+
/**
* Invoked on start with valid flags and tx state.
*
More information about the Mulgara-svn
mailing list