jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1213707 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/version/ test/java/org/apache/jackrabbit/core/version/
Date Tue, 13 Dec 2011 14:23:07 GMT
Author: reschke
Date: Tue Dec 13 14:23:07 2011
New Revision: 1213707

URL: http://svn.apache.org/viewvc?rev=1213707&view=rev
Log:
JCR-2930: same named child nodes disappear on restore

fix restore logic to take SNS into account

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java?rev=1213707&r1=1213706&r2=1213707&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImplRestore.java
Tue Dec 13 14:23:07 2011
@@ -16,11 +16,7 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.PropertyType;
@@ -473,6 +469,19 @@ abstract public class VersionManagerImpl
         // need to sync with state manager
         state.store();
 
+        // create a map that contains a int->NodeStateEx mapping for each child name
+        Map<Name, Map<Integer, NodeStateEx>> entryToNodeStateExMapping = new
HashMap<Name, Map<Integer, NodeStateEx>>();
+        for (ChildNodeEntry entry : state.getState().getChildNodeEntries()) {
+            Map<Integer, NodeStateEx> id2stateMap = entryToNodeStateExMapping
+                    .get(entry.getName());
+            if (id2stateMap == null) {
+                id2stateMap = new HashMap<Integer, NodeStateEx>();
+            }
+            id2stateMap.put(entry.getIndex(),
+                    state.getNode(entry.getName(), entry.getIndex()));
+            entryToNodeStateExMapping.put(entry.getName(), id2stateMap);
+        }
+
         // For each child node C present on F:
         // - F will never have a child node with an OPV of IGNORE, INITIALIZE,
         //   COMPUTE or ABORT (see 15.2 Check-In: Creating a Version).
@@ -494,7 +503,12 @@ abstract public class VersionManagerImpl
                 InternalFrozenNode f = (InternalFrozenNode) child;
 
                 // if node is present, remove it
-                state.removeNode(entry.getName(), entry.getIndex());
+                Map<Integer, NodeStateEx> id2stateMap = entryToNodeStateExMapping
+                        .get(entry.getName());
+                if (id2stateMap != null
+                        && id2stateMap.containsKey(entry.getIndex())) {
+                    state.removeNode(id2stateMap.get(entry.getIndex()));
+                }
 
                 // check for existing
                 if (f.getFrozenId() != null) {

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java?rev=1213707&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java
Tue Dec 13 14:23:07 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.version;
+
+import javax.jcr.Node;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionManager;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * Test case for JCR-2930
+ */
+public class RestoreNodeWithSNSTest extends AbstractJCRTest {
+
+    public void testRestoreWithSNS() throws Exception {
+        
+        int childCount = 5;
+        
+        // create a test node with /childCount/ children with the same name
+        Node n = testRootNode.addNode(nodeName1);
+        n.addMixin(mixVersionable);
+        for (int i = 0; i < childCount; i++) {
+            Node child = n.addNode(nodeName2);
+            child.setProperty("name", nodeName2 + i);
+        }
+        testRootNode.getSession().save();
+
+        // check the number of children
+        assertEquals(childCount, n.getNodes().getSize());
+
+        VersionManager vm = testRootNode.getSession().getWorkspace()
+                .getVersionManager();
+        vm.checkin(n.getPath());
+
+        // modify one child
+        vm.checkout(n.getPath());
+        n.getNode(nodeName2).setProperty("name", "modified");
+        testRootNode.getSession().save();
+
+        // check the number of children again
+        assertEquals(childCount, n.getNodes().getSize());
+
+        // restore base versiob
+        Version baseVersion = vm.getBaseVersion(n.getPath());
+        vm.restore(baseVersion, true);
+
+        n.getSession().refresh(false);
+
+        // check the number of children again
+        assertEquals(childCount, n.getNodes().getSize());
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/RestoreNodeWithSNSTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java?rev=1213707&r1=1213706&r2=1213707&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/TestAll.java
Tue Dec 13 14:23:07 2011
@@ -36,6 +36,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(InternalVersionHistoryImplTest.class);
         suite.addTestSuite(RemoveVersionLabelTest.class);
         suite.addTestSuite(RestoreTest.class);
+        suite.addTestSuite(RestoreNodeWithSNSTest.class);
         suite.addTestSuite(VersionIteratorImplTest.class);
         return suite;
     }



Mime
View raw message