Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 98747 invoked from network); 23 Sep 2010 11:15:35 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Sep 2010 11:15:35 -0000 Received: (qmail 53007 invoked by uid 500); 23 Sep 2010 11:15:35 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 52904 invoked by uid 500); 23 Sep 2010 11:15:32 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 52889 invoked by uid 99); 23 Sep 2010 11:15:31 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 11:15:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 11:15:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A53A3238890B; Thu, 23 Sep 2010 11:14:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100923111451.A53A3238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 element : entry.getElements()) { - Iterator> iter = element.getChildren(); - while (iter.hasNext()) { - PathMap.Element child = iter.next(); + for (PathMap.Element element + : getCachedPaths(modified.getNodeId())) { + for (PathMap.Element 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> 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>(); boolean orderChanged = false; - Iterator> iter = parent.getChildren(); - while (iter.hasNext()) { - PathMap.Element child = iter.next(); + for (PathMap.Element 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 + * JCR-2720 + */ + 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 { * Return an iterator over all of this element's children. Every * element returned by this iterator is of type {@link Element}. */ - public Iterator> getChildren() { + public List> getChildren() { ArrayList> result = new ArrayList>(); if (children != null) { for (List> list : children.values()) { @@ -614,7 +613,7 @@ public class PathMap { } } } - return result.iterator(); + return result; } /**