jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r577871 - in /jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: TransactionContext.java XASessionImpl.java
Date Thu, 20 Sep 2007 18:52:07 GMT
Author: jukka
Date: Thu Sep 20 11:52:06 2007
New Revision: 577871

URL: http://svn.apache.org/viewvc?rev=577871&view=rev
Log:
1.3: Merged revision 572595 (JCR-1109)

Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=577871&r1=577870&r2=577871&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Thu Sep 20 11:52:06 2007
@@ -60,6 +60,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
@@ -259,5 +264,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/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=577871&r1=577870&r2=577871&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
Thu Sep 20 11:52:06 2007
@@ -226,23 +226,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);
         }
@@ -272,18 +274,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);
         }



Mime
View raw message