jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r794100 - in /jackrabbit/branches/1.5: jackrabbit-jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-spi/src/main/java/org/apache/jackrab...
Date Tue, 14 Jul 2009 22:38:09 GMT
Author: mduerig
Date: Tue Jul 14 22:38:08 2009
New Revision: 794100

URL: http://svn.apache.org/viewvc?rev=794100&view=rev
Log:
JCR-1797: RepositoryService.getItemInfos should be allowed to return entries outside of the
requested tree.

Modified:
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/pom.xml
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
    jackrabbit/branches/1.5/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/branches/1.5/jackrabbit-spi2jcr/pom.xml

Modified: jackrabbit/branches/1.5/jackrabbit-jcr2spi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/pom.xml?rev=794100&r1=794099&r2=794100&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/pom.xml (original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/pom.xml Tue Jul 14 22:38:08 2009
@@ -33,7 +33,7 @@
     <relativePath>../jackrabbit-parent/pom.xml</relativePath>
   </parent>
   <artifactId>jackrabbit-jcr2spi</artifactId>
-  <version>1.5.5</version>
+  <version>1.5.7</version>
   <name>Jackrabbit JCR to SPI</name>
 
   <scm>

Modified: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=794100&r1=794099&r2=794100&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Tue Jul 14 22:38:08 2009
@@ -195,46 +195,41 @@
     private synchronized NodeState createItemStates(NodeId nodeId, Iterator itemInfos,
                                                     NodeEntry entry, boolean isDeep)
             throws ItemNotFoundException, RepositoryException {
-        NodeState nodeState = null;
+        NodeState nodeState;
         ItemInfos infos = new ItemInfos(itemInfos);
+        // first entry in the iterator is the originally requested Node.
+        if (infos.hasNext()) {
+            NodeInfo first = (NodeInfo) infos.next();
+            if (isDeep) {
+                // for a deep state, the hierarchy entry does not correspond to
+                // the given NodeEntry -> retrieve NodeState before executing
+                // validation check.
+                nodeState = createDeepNodeState(first, entry, infos);
+                assertValidState(nodeState, first);
+            } else {
+                // 'isDeep' == false -> the given NodeEntry must match to the
+                // first ItemInfo retrieved from the iterator.
+                assertMatchingPath(first, entry);
+                nodeState = createNodeState(first, entry);
+            }
+        } else {
+            // empty iterator
+            throw new ItemNotFoundException("Node with id " + nodeId + " could not be found.");
+        }
 
+        // deal with all additional ItemInfos that may be present.
         // Assuming locality of the itemInfos, we keep an estimate of a parent entry.
         // This reduces the part of the hierarchy to traverse. For large batches this
         // optimization results in about 25% speed up.
-        NodeEntry aproxParentEntry = entry;
-
+        NodeEntry approxParentEntry = nodeState.getNodeEntry();
         while (infos.hasNext()) {
             ItemInfo info = (ItemInfo) infos.next();
             if (info.denotesNode()) {
-                NodeInfo nodeInfo = (NodeInfo) info;
-
-                if (nodeId.equals(nodeInfo.getId())) {
-                    // This is the originally requested node
-                    if (isDeep) {
-                        // for a deep state, the hierarchy entry does not correspond to
-                        // the given NodeEntry -> retrieve NodeState before executing
-                        // validation check.
-                        nodeState = createDeepNodeState(nodeInfo, entry, infos);
-                        assertValidState(nodeState, nodeInfo);
-                    } else {
-                        // 'isDeep' == false -> the given NodeEntry must match the
-                        // ItemInfo for the originally requested node
-                        assertMatchingPath(nodeInfo, entry);
-                        nodeState = createNodeState(nodeInfo, entry);
-                    }
-                } else {
-                    // deal with additional nodeInfo
-                    aproxParentEntry = createDeepNodeState(nodeInfo, aproxParentEntry, infos).getNodeEntry();
-                }
+                approxParentEntry = createDeepNodeState((NodeInfo) info, approxParentEntry,
infos).getNodeEntry();
             } else {
-                // deal with additional propertyInfo
-                createDeepPropertyState((PropertyInfo) info, aproxParentEntry, infos);
+                createDeepPropertyState((PropertyInfo) info, approxParentEntry, infos);
             }
         }
-
-        if (nodeState == null) {
-            throw new ItemNotFoundException("Node with id " + nodeId + " could not be found.");
-        }
         return nodeState;
     }
 
@@ -373,12 +368,13 @@
                     // until the smallest common root is found
                     entry = entry.getParent();
                 }
-                else {
+                else if (missingElems[i].denotesName()) {
                     // Add missing elements starting from the smallest common root
                     Name name = missingElems[i].getName();
                     int index = missingElems[i].getNormalizedIndex();
                     entry = createIntermediateNodeEntry(entry, name, index, infos);
                 }
+                // else denotesCurrent -> ignore
             }
             if (entry == anyParent) {
                 throw new RepositoryException("Internal error while getting deep itemState");
@@ -422,12 +418,13 @@
                     // until the smallest common root is found
                     entry = entry.getParent();
                 }
-                else {
+                else if (missingElems[i].denotesName()) {
                     // Add missing elements starting from the smallest common root
                     Name name = missingElems[i].getName();
                     int index = missingElems[i].getNormalizedIndex();
                     entry = createIntermediateNodeEntry(entry, name, index, infos);
                 }
+                // else denotesCurrent -> ignore
                 i++;
             }
             // create PropertyEntry for the last element if not existing yet
@@ -499,7 +496,7 @@
 
     /**
      * Returns true if the given <code>missingElems</code> start with
-     * a current (.) or the root element, in which case the info is not within
+     * the root element, in which case the info is not within
      * the tree as it is expected.
      * See also #JCR-1797 for the corresponding enhancement request.
      *
@@ -508,7 +505,7 @@
      */
     private static boolean startsWithIllegalElement(Path.Element[] missingElems) {
         if (missingElems.length > 0) {
-            return !(missingElems[0].denotesName() || missingElems[0].denotesParent());
+            return missingElems[0].denotesRoot();
         }
         return false;
     }

Modified: jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java?rev=794100&r1=794099&r2=794100&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
(original)
+++ jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
Tue Jul 14 22:38:08 2009
@@ -83,39 +83,23 @@
     private Iterable itemInfosProvider;
 
     /**
-     * Check whether we can traverse the hierarchy when the item infos are returned in their
-     * canonical order.
-     * @throws RepositoryException
-     */
-    public void testGetItemInfos() throws RepositoryException {
-        itemInfosProvider = new Iterable() {
-            public Iterator iterator() {
-                return itemInfos.iterator();
-            }
-        };
-
-        checkHierarchy();
-    }
-
-    /**
      * Check whether we can traverse the hierarchy when the item info for root is
-     * returned first.
+     * retrieved first.
      * @throws RepositoryException
      */
     public void testGetItemInfosRootFirst() throws RepositoryException {
         itemInfosProvider = new Iterable() {
+            Predicate isRoot = new Predicate() {
+                public boolean evaluate(Object object) {
+                    ItemInfo itemInfo = (ItemInfo) object;
+                    return itemInfo.getPath().denotesRoot();
+                }
+            };
 
             public Iterator iterator() {
-                Predicate isRoot = new Predicate() {
-                    public boolean evaluate(Object object) {
-                        ItemInfo itemInfo = (ItemInfo) object;
-                        return itemInfo.getPath().denotesRoot();
-                    }
-                };
-
                 return new IteratorChain(
-                    new FilterIterator(itemInfos.iterator(), isRoot),
-                    new FilterIterator(itemInfos.iterator(), NotPredicate.getInstance(isRoot)));
+                        new FilterIterator(itemInfos.iterator(), isRoot),
+                        new FilterIterator(itemInfos.iterator(), NotPredicate.getInstance(isRoot)));
             }
         };
 
@@ -124,28 +108,29 @@
     }
 
     /**
-     * Check whether we can traverse the hierarchy when the item info for root is
-     * returned last.
+     * Check whether we can traverse the hierarchy when the item info for a deep item
+     * is retrieved first.
      * @throws RepositoryException
      */
-    public void testGetItemInfosRootLast() throws RepositoryException {
+    public void testGetItemInfosDeepFirst() throws RepositoryException {
+        final String targetPath = "/node2/node21/node211/node2111/node21111/node211111/node2111111";
+
         itemInfosProvider = new Iterable() {
+            Predicate isTarget = new Predicate() {
+                public boolean evaluate(Object object) {
+                    ItemInfo itemInfo = (ItemInfo) object;
+                    return targetPath.equals(toJCRPath(itemInfo.getPath()));
+                }
+            };
 
             public Iterator iterator() {
-                Predicate isRoot = new Predicate() {
-                    public boolean evaluate(Object object) {
-                        ItemInfo itemInfo = (ItemInfo) object;
-                        return itemInfo.getPath().denotesRoot();
-                    }
-                };
-
                 return new IteratorChain(
-                    new FilterIterator(itemInfos.iterator(), NotPredicate.getInstance(isRoot)),
-                    new FilterIterator(itemInfos.iterator(), isRoot));
+                        new FilterIterator(itemInfos.iterator(), isTarget),
+                        new FilterIterator(itemInfos.iterator(), NotPredicate.getInstance(isTarget)));
             }
         };
 
-        assertTrue(session.getRootNode().getDepth() == 0);
+        assertEquals(targetPath, session.getItem(targetPath).getPath());
         checkHierarchy();
     }
 

Modified: jackrabbit/branches/1.5/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=794100&r1=794099&r2=794100&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/branches/1.5/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Tue Jul 14 22:38:08 2009
@@ -261,16 +261,20 @@
     public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException,
RepositoryException;
 
     /**
-     * Method used to 'batch-read' from the persistent storage. It must contain
-     * the <code>NodeInfo</code> for the given <code>NodeId</code>
in the
-     * <code>Iterator</code>. In addition the iterator may contain arbitrary
-     * child <code>ItemInfo</code>s from the entire hierarchy.
+     * Method used to 'batch-read' from the persistent storage. It returns the
+     * <code>NodeInfo</code> for the given <code>NodeId</code> as
the first
+     * element in the <code>Iterator</code>. In addition the iterator may contain
+     * child <code>ItemInfo</code>s down to a certain depth. The configuration
+     * process however is left to the implementation.
      *
      * @param sessionInfo
      * @param nodeId
      * @return An <code>Iterator</code> of <code>ItemInfo</code>s
containing
      * at least a single element: the <code>NodeInfo</code> that represents
-     * the Node identified by the given <code>NodeId</code>.
+     * the Node identified by the given <code>NodeId</code>. If the Iterator
+     * contains multiple elements, the first is expected to represent the Node
+     * identified by the given <code>NodeId</code> and all subsequent elements
+     * must represent children of that <code>Node</code>.
      * @throws javax.jcr.ItemNotFoundException
      * @throws javax.jcr.RepositoryException
      * @see javax.jcr.Session#getItem(String)

Modified: jackrabbit/branches/1.5/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.5/jackrabbit-spi2jcr/pom.xml?rev=794100&r1=794099&r2=794100&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/branches/1.5/jackrabbit-spi2jcr/pom.xml Tue Jul 14 22:38:08 2009
@@ -143,14 +143,14 @@
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr2spi</artifactId>
-      <version>1.5.0</version>
+      <version>1.5.7</version>
       <classifier>tests</classifier>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-jcr2spi</artifactId>
-      <version>1.5.0</version>
+      <version>1.5.7</version>
       <classifier></classifier>
       <scope>test</scope>
     </dependency>



Mime
View raw message