jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sch...@apache.org
Subject svn commit: r1327476 - in /jackrabbit/branches/2.2/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/state/ test/java/org/apache/jackrabbit/core/
Date Wed, 18 Apr 2012 12:32:51 GMT
Author: schans
Date: Wed Apr 18 12:32:50 2012
New Revision: 1327476

URL: http://svn.apache.org/viewvc?rev=1327476&view=rev
Log:
JCR-3290: Mix data inconsistency by correctly merging transient state with persistent overlayed
state (patch applied from trunk)

Added:
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
      - copied, changed from r1324713, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
Modified:
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java?rev=1327476&r1=1327475&r2=1327476&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/NodeStateMerger.java
Wed Apr 18 12:32:50 2012
@@ -39,6 +39,7 @@ import java.util.Set;
  * on different <code>NodeState</code> instances representing the same node.
  * <p/>
  * See http://issues.apache.org/jira/browse/JCR-584.
+ * See also http://issues.apache.org/jira/browse/JCR-3290.
  */
 class NodeStateMerger {
 
@@ -113,8 +114,8 @@ class NodeStateMerger {
                     ArrayList<ChildNodeEntry> removed = new ArrayList<ChildNodeEntry>();
 
                     for (ChildNodeEntry cne : state.getAddedChildNodeEntries()) {
-
-                        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())) {
@@ -346,6 +347,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())) {
@@ -374,6 +383,7 @@ class NodeStateMerger {
         boolean isDeleted(ItemId id);
         boolean isModified(ItemId id);
         boolean allowsSameNameSiblings(NodeId id);
+        NodeState getNodeState(NodeId id) throws ItemStateException;
         EffectiveNodeType getEffectiveNodeType(Name ntName) throws NoSuchNodeTypeException;
     }
 }

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=1327476&r1=1327475&r2=1327476&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Wed Apr 18 12:32:50 2012
@@ -647,7 +647,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);
@@ -1318,7 +1318,7 @@ public class SharedItemStateManager
                 if (parentId == null && oldParentId == null) {
                     // The root node can be ignored
 
-                } else if (!parentId.equals(oldParentId)) {
+                } else if (parentId != null && !parentId.equals(oldParentId)) {
 
                     // This node has been moved, check whether the parent has been modified
aswell
                     if (changeLog.has(parentId)) {
@@ -1403,7 +1403,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);
         }

Copied: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
(from r1324713, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java?p2=jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java&p1=jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java&r1=1324713&r2=1327476&rev=1327476&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/AddMoveTest.java
Wed Apr 18 12:32:50 2012
@@ -20,15 +20,15 @@ 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();
@@ -40,11 +40,6 @@ public class AddMoveTest extends Abstrac
         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();
@@ -56,10 +51,7 @@ public class AddMoveTest extends Abstrac
         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);
+        // TODO: Should run consistency check here when it's available in 2.2.
+
     }
 }



Mime
View raw message