You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/11/08 23:21:35 UTC

svn commit: r1032770 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/state/ChangeLog.java test/java/org/apache/jackrabbit/core/XATest.java

Author: jukka
Date: Mon Nov  8 22:21:34 2010
New Revision: 1032770

URL: http://svn.apache.org/viewvc?rev=1032770&view=rev
Log:
JCR-2796: Restoring a node fails (partially) if done within a XA transaction

The restore operation can produce a ChangeLog that both adds and removes
(instead of just modifying) the same item states. The internal caching
logic expects this behaviour, but the ChangeLog.merge() logic used in
transactions would automatically convert such add/remove pairs to
individual modifications. This change modifies the merge() logic to
leave such add/remove pairs intact.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java?rev=1032770&r1=1032769&r2=1032770&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java Mon Nov  8 22:21:34 2010
@@ -265,20 +265,9 @@ public class ChangeLog {
             }
         }
 
-        // add 'added' state, but respect previously deleted
+        // add 'added' states
         for (ItemState state : other.addedStates()) {
-            ItemState deletedState = deletedStates.remove(state.getId());
-            if (deletedState != null) {
-                // the newly 'added' state had previously been deleted;
-                // merging those two operations results in a modified state
-
-                // adapt status/modCount and add to modified
-                state.setStatus(deletedState.getStatus());
-                state.setModCount(deletedState.getModCount());
-                modifiedStates.put(state.getId(), state);
-            } else {
-                addedStates.put(state.getId(), state);
-            }
+            addedStates.put(state.getId(), state);
         }
 
         // add refs

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java?rev=1032770&r1=1032769&r2=1032770&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/XATest.java Mon Nov  8 22:21:34 2010
@@ -28,6 +28,7 @@ import javax.jcr.Property;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.NodeType;
@@ -107,6 +108,47 @@ public class XATest extends AbstractJCRT
 
     /**
      * Test case for
+     * <a href="https://issues.apache.org/jira/browse/JCR-2796">JCR-2796</a>.
+     */
+    public void testRestore() throws Exception {
+        Session session = getHelper().getSuperuserSession();
+        try {
+            VersionManager vm = session.getWorkspace().getVersionManager();
+
+            // make sure that 'testNode' does not exist at the beginning
+            // of the test
+            while (session.nodeExists("/testNode")) {
+                session.getNode("/testNode").remove();
+                session.save();
+            }
+
+            // 1) create 'testNode' that has a child and a grandchild
+            Node node = session.getRootNode().addNode("testNode");
+            node.addMixin(NodeType.MIX_VERSIONABLE);
+            node.addNode("child").addNode("grandchild");
+            session.save();
+
+            // 2) check in 'testNode' and give a version-label
+            Version version = vm.checkin(node.getPath());
+            vm.getVersionHistory(node.getPath()).addVersionLabel(
+                    version.getName(), "testLabel", false);
+
+            // 3) do restore by label
+            UserTransaction utx = new UserTransactionImpl(session);
+            utx.begin();
+            vm.restoreByLabel(node.getPath(), "testLabel", true);
+            utx.commit();
+
+            // 4) try to get the grandchild (fails if the restoring has
+            // been done within a transaction)
+            assertTrue(node.hasNode("child/grandchild"));
+        } finally {
+            session.logout();
+        }
+    }
+
+    /**
+     * Test case for
      * <a href="https://issues.apache.org/jira/browse/JCR-2712">JCR-2712</a>.
      */
     public void testVersioningRollbackWithoutPrepare() throws Exception {