jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1000408 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/test/java/org/apache/jackrabbit/core/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/
Date Thu, 23 Sep 2010 11:14:51 GMT
Author: jukka
Date: Thu Sep 23 11:14:51 2010
New Revision: 1000408

URL: http://svn.apache.org/viewvc?rev=1000408&view=rev
Log:
JCR-2720: Changes from Session.move() to a top-level node aren't seen in a second session

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=1000408&r1=1000407&r2=1000408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Thu Sep 23 11:14:51 2010
@@ -17,8 +17,11 @@
 package org.apache.jackrabbit.core;
 
 import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
@@ -306,27 +309,21 @@ public class CachingHierarchyManager ext
      */
     public void nodeModified(NodeState modified) {
         synchronized (cacheMonitor) {
-            LRUEntry entry = (LRUEntry) idCache.get(modified.getNodeId());
-            if (entry == null) {
-                // Item not cached, ignore
-                return;
-            }
-            for (PathMap.Element<LRUEntry> element : entry.getElements()) {
-                Iterator<PathMap.Element<LRUEntry>> iter = element.getChildren();
-                while (iter.hasNext()) {
-                    PathMap.Element<LRUEntry> child = iter.next();
+            for (PathMap.Element<LRUEntry> element
+                    : getCachedPaths(modified.getNodeId())) {
+                for (PathMap.Element<LRUEntry> child : element.getChildren()) {
                     ChildNodeEntry cne = modified.getChildNodeEntry(
                             child.getName(), child.getNormalizedIndex());
                     if (cne == null) {
                         // Item does not exist, remove
                         evict(child, true);
-                        continue;
-                    }
-
-                    LRUEntry childEntry = child.get();
-                    if (childEntry != null && !cne.getId().equals(childEntry.getId()))
{
-                        // Different child item, remove
-                        evict(child, true);
+                    } else {
+                        LRUEntry childEntry = child.get();
+                        if (childEntry != null
+                                && !cne.getId().equals(childEntry.getId())) {
+                            // Different child item, remove
+                            evict(child, true);
+                        }
                     }
                 }
             }
@@ -334,6 +331,21 @@ public class CachingHierarchyManager ext
         }
     }
 
+    private List<PathMap.Element<LRUEntry>> getCachedPaths(NodeId id) {
+        // JCR-2720: Handle the root path as a special case
+        if (rootNodeId.equals(id)) {
+            return Collections.singletonList(pathCache.map(
+                    PathFactoryImpl.getInstance().getRootPath(), true));
+        }
+
+        LRUEntry entry = (LRUEntry) idCache.get(id);
+        if (entry != null) {
+            return Arrays.asList(entry.getElements());
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -400,39 +412,33 @@ public class CachingHierarchyManager ext
                     new HashMap<Path.Element, PathMap.Element<LRUEntry>>();
                 boolean orderChanged = false;
 
-                Iterator<PathMap.Element<LRUEntry>> iter = parent.getChildren();
-                while (iter.hasNext()) {
-                    PathMap.Element<LRUEntry> child = iter.next();
+                for (PathMap.Element<LRUEntry> child : parent.getChildren()) {
                     LRUEntry childEntry = (LRUEntry) child.get();
                     if (childEntry == null) {
-                        /**
-                         * Child has no associated UUID information: we're
-                         * therefore unable to determine if this child's
-                         * position is still accurate and have to assume
-                         * the worst and remove it.
-                         */
-                        evict(child, false);
-                        continue;
-                    }
-                    NodeId childId = childEntry.getId();
-                    ChildNodeEntry cne = state.getChildNodeEntry(childId);
-                    if (cne == null) {
-                        /* Child no longer in parent node state, so remove it */
+                        // Child has no associated UUID information: we're
+                        // therefore unable to determine if this child's
+                        // position is still accurate and have to assume
+                        // the worst and remove it.
                         evict(child, false);
-                        continue;
-                    }
-
-                    /**
-                     * Put all children into map of new children order - regardless
-                     * whether their position changed or not - as we might need
-                     * to reorder them later on.
-                     */
-                    Path.Element newNameIndex = PathFactoryImpl.getInstance().createElement(
-                            cne.getName(), cne.getIndex());
-                    newChildrenOrder.put(newNameIndex, child);
-
-                    if (!newNameIndex.equals(child.getPathElement())) {
-                        orderChanged = true;
+                    } else {
+                        NodeId childId = childEntry.getId();
+                        ChildNodeEntry cne = state.getChildNodeEntry(childId);
+                        if (cne == null) {
+                            // Child no longer in parent node, so remove it
+                            evict(child, false);
+                        } else {
+                            // Put all children into map of new children order
+                            // - regardless whether their position changed or
+                            // not - as we might need to reorder them later on.
+                            Path.Element newNameIndex =
+                                PathFactoryImpl.getInstance().createElement(
+                                        cne.getName(), cne.getIndex());
+                            newChildrenOrder.put(newNameIndex, child);
+
+                            if (!newNameIndex.equals(child.getPathElement())) {
+                                orderChanged = true;
+                            }
+                        }
                     }
                 }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java?rev=1000408&r1=1000407&r2=1000408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/MoveTest.java
Thu Sep 23 11:14:51 2010
@@ -28,6 +28,38 @@ import org.apache.jackrabbit.test.Abstra
 public class MoveTest extends AbstractJCRTest {
 
     /**
+     * Test case for
+     * <a href="https://issues.apache.org/jira/browse/JCR-2720">JCR-2720</a>
+     */
+    public void testMoveVisibilityAcrossSessions() throws RepositoryException {
+        Session session1 = getHelper().getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
+
+        if (session1.itemExists("/foo")) {
+            session1.removeItem("/foo");
+            session1.save();
+        }
+
+        session1.getRootNode().addNode("libs").addNode("foo").addNode("install");
+        session1.save();
+
+        assertTrue(session1.itemExists("/libs/foo/install"));
+        assertFalse(session1.itemExists("/foo"));
+
+        assertTrue(session2.itemExists("/libs/foo/install"));
+        assertFalse(session2.itemExists("/foo"));
+
+        session1.move("/libs", "/foo");
+        session1.save();
+
+        assertFalse(session1.itemExists("/libs/foo/install"));
+
+        session2.refresh(false);
+
+        assertFalse("JCR-2720", session2.itemExists("/libs/foo/install"));
+    }
+
+    /**
      * Tests moving a node, and then refreshing or saving it.
      */
     public void testMove() throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java?rev=1000408&r1=1000407&r2=1000408&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java
Thu Sep 23 11:14:51 2010
@@ -25,7 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 
 
 /**
@@ -603,7 +602,7 @@ public class PathMap<T> {
          * Return an iterator over all of this element's children. Every
          * element returned by this iterator is of type {@link Element}.
          */
-        public Iterator<Element<T>> getChildren() {
+        public List<Element<T>> getChildren() {
             ArrayList<Element<T>> result = new ArrayList<Element<T>>();
             if (children != null) {
                 for (List<Element<T>> list : children.values()) {
@@ -614,7 +613,7 @@ public class PathMap<T> {
                     }
                 }
             }
-            return result.iterator();
+            return result;
         }
 
         /**



Mime
View raw message