You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by dp...@apache.org on 2007/09/04 11:48:45 UTC
svn commit: r572595 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core:
TransactionContext.java XASessionImpl.java
Author: dpfister
Date: Tue Sep 4 02:48:44 2007
New Revision: 572595
URL: http://svn.apache.org/viewvc?rev=572595&view=rev
Log:
JCR-1109 - Resource association not compliant to JTA spec
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=572595&r1=572594&r2=572595&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java Tue Sep 4 02:48:44 2007
@@ -66,6 +66,11 @@
private int status;
/**
+ * Flag indicating whether the association is currently suspended.
+ */
+ private boolean suspended;
+
+ /**
* Create a new instance of this class.
* @param resources transactional resources
* @param timeout timeout, in seconds
@@ -264,5 +269,24 @@
for (int i = 0; i < resources.length; i++) {
resources[i].afterOperation(this);
}
+ }
+
+ /**
+ * Return a flag indicating whether the association is suspended.
+ *
+ * @return <code>true</code> if the association is suspended;
+ * <code>false</code> otherwise
+ */
+ public boolean isSuspended() {
+ return suspended;
+ }
+
+ /**
+ * Set a flag indicating whether the association is suspended.
+ *
+ * @param suspended flag whether that the association is suspended.
+ */
+ public void setSuspended(boolean suspended) {
+ this.suspended = suspended;
}
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=572595&r1=572594&r2=572595&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java Tue Sep 4 02:48:44 2007
@@ -233,23 +233,25 @@
log.error("Resource already associated with a transaction.");
throw new XAException(XAException.XAER_PROTO);
}
- TransactionContext tx;
+ TransactionContext tx = (TransactionContext) txGlobal.get(xid);
if (flags == TMNOFLAGS) {
- tx = (TransactionContext) txGlobal.get(xid);
if (tx != null) {
throw new XAException(XAException.XAER_DUPID);
}
tx = createTransaction(xid);
} else if (flags == TMJOIN) {
- tx = (TransactionContext) txGlobal.get(xid);
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
} else if (flags == TMRESUME) {
- tx = (TransactionContext) txGlobal.get(xid);
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
+ if (!tx.isSuspended()) {
+ log.error("Unable to resume: transaction not suspended.");
+ throw new XAException(XAException.XAER_PROTO);
+ }
+ tx.setSuspended(false);
} else {
throw new XAException(XAException.XAER_INVAL);
}
@@ -279,18 +281,33 @@
* from the transaction specified.
* All other flags generate an <code>XAException</code> of type
* <code>XAER_INVAL</code>
+ * <p/>
+ * It is legal for a transaction association to be suspended and then
+ * ended (either with <code>TMSUCCESS</code> or <code>TMFAIL</code>)
+ * without having been resumed again.
*/
public void end(Xid xid, int flags) throws XAException {
- if (!isAssociated()) {
- log.error("Resource not associated with a transaction.");
- throw new XAException(XAException.XAER_PROTO);
- }
TransactionContext tx = (TransactionContext) txGlobal.get(xid);
if (tx == null) {
throw new XAException(XAException.XAER_NOTA);
}
- if (flags == TMSUCCESS || flags == TMFAIL || flags == TMSUSPEND) {
+ if (flags == TMSUSPEND) {
+ if (!isAssociated()) {
+ log.error("Resource not associated with a transaction.");
+ throw new XAException(XAException.XAER_PROTO);
+ }
associate(null);
+ tx.setSuspended(true);
+ } else if (flags == TMFAIL || flags == TMSUCCESS) {
+ if (!tx.isSuspended()) {
+ if (!isAssociated()) {
+ log.error("Resource not associated with a transaction.");
+ throw new XAException(XAException.XAER_PROTO);
+ }
+ associate(null);
+ } else {
+ tx.setSuspended(false);
+ }
} else {
throw new XAException(XAException.XAER_INVAL);
}