jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sch...@apache.org
Subject svn commit: r1324713 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java test/java/org/apache/jackrabbit/core/AddMoveTest.java
Date Wed, 11 Apr 2012 11:51:29 GMT
Author: schans
Date: Wed Apr 11 11:51:28 2012
New Revision: 1324713

URL: http://svn.apache.org/viewvc?rev=1324713&view=rev
Log:
JCR-3290: Mix data inconsistency by correctly merging transient state with persistent overlayed
state

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java?rev=1324713&r1=1324712&r2=1324713&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
Wed Apr 11 11:51:28 2012
@@ -44,6 +44,7 @@ class NodeStateMerger {
      * in order to avoid an <code>InvalidItemStateException</code>.
      * <p/>
      * See http://issues.apache.org/jira/browse/JCR-584.
+     * See also http://issues.apache.org/jira/browse/JCR-3290.
      *
      * @param state node state whose modified overlayed state should be
      *        merged
@@ -109,8 +110,8 @@ class NodeStateMerger {
                     ArrayList<ChildNodeEntry> removed = new ArrayList<ChildNodeEntry>();
 
                     for (ChildNodeEntry cne : state.getAddedChildNodeEntries()) {
-                        // locally added?
-                        if (context.isAdded(cne.getId()) || context.isModified(cne.getId()))
{
+                        // locally added or moved?
+                        if (context.isAdded(cne.getId()) || (context.isModified(cne.getId())
&& isParent(state, cne, context))) {
                             // a new child node entry has been added to this state;
                             // check for name collisions with other state
                             if (overlayedState.hasChildNodeEntry(cne.getName())) {
@@ -339,6 +340,14 @@ class NodeStateMerger {
         return false;
     }
 
+    private static boolean isParent(NodeState state, ChildNodeEntry entry, MergeContext context)
{
+        try {
+            return state.getId().equals(context.getNodeState(entry.getId()).getParentId());
+        } catch (ItemStateException e) {
+            return false;
+        }
+    }
+
     private static boolean isAutoCreated(ChildNodeEntry cne, EffectiveNodeType ent) {
         for (QNodeDefinition def : ent.getAutoCreateNodeDefs()) {
             if (def.getName().equals(cne.getName())) {
@@ -368,5 +377,6 @@ class NodeStateMerger {
         boolean isModified(ItemId id);
         boolean allowsSameNameSiblings(NodeId id);
         EffectiveNodeType getEffectiveNodeType(Name ntName) throws NoSuchNodeTypeException;
+        NodeState getNodeState(NodeId id) throws ItemStateException;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1324713&r1=1324712&r2=1324713&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Wed Apr 11 11:51:28 2012
@@ -655,7 +655,7 @@ public class SharedItemStateManager
                                             return ntReg.getEffectiveNodeType(ntName);
                                         }
 
-                                        protected NodeState getNodeState(NodeId id)
+                                        public NodeState getNodeState(NodeId id)
                                                 throws ItemStateException {
                                             if (local.has(id)) {
                                                 return (NodeState) local.get(id);
@@ -1320,7 +1320,7 @@ public class SharedItemStateManager
                 }
 
                 if (!(parentId == null && oldParentId == null)
-                        && !parentId.equals(oldParentId)) {
+                        && (parentId != null && !parentId.equals(oldParentId)))
{
                     // This node (not the root) has been moved; check
                     // whether the parent has been modified as well
                     if (changeLog.has(parentId)) {
@@ -1405,7 +1405,7 @@ public class SharedItemStateManager
             if (sharedSet.contains(expectedParent)) {
                 return;
             }
-            String message = "Child node has another parent id " + parentId + ", expected
" + expectedParent;
+            String message = "Child node " + childState.getId() + " has another parent id
" + parentId + ", expected " + expectedParent;
             log.error(message);
             throw new ItemStateException(message);
         }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java?rev=1324713&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
Wed Apr 11 11:51:28 2012
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.core.persistence.check.ConsistencyReport;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+public class AddMoveTest extends AbstractJCRTest {
+
+    private String folder1Path;
+    private String folder2Path;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        Node folder1 = testRootNode.addNode("folder1");
+        folder1Path = folder1.getPath();
+        Node folder2 = testRootNode.addNode("folder2");
+        folder2Path = folder2.getPath();
+        folder1.addNode("node1");
+        testRootNode.getSession().save();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testAddMove() throws RepositoryException, NotExecutableException {
+        Session session1 = getHelper().getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
+
+        session1.getNode(folder1Path).addNode("node2");
+        session2.move(folder1Path + "/node1", folder2Path + "/node1");
+        session2.save();
+        Node node = session1.getNode(folder2Path + "/node1");
+        node.setProperty("foo", "bar");
+        session1.save();
+
+        ConsistencyReport consistencyReport = TestHelper.checkConsistency(testRootNode.getSession(),
false, null);
+        //for (ReportItem item : consistencyReport.getItems()) {
+        //    System.out.println(item.getMessage());
+        //}
+        assertTrue(consistencyReport.getItems().size() == 0);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message