jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r794302 - in /jackrabbit/trunk: ./ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/test/resources/ jackrabbit-jcr2spi/src/test/reso...
Date Wed, 15 Jul 2009 15:38:00 GMT
Author: mduerig
Date: Wed Jul 15 15:37:59 2009
New Revision: 794302

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

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
      - copied, changed from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
      - copied, changed from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/
      - copied from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/org/
      - copied from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/org/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/org/apache/
      - copied from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/org/apache/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/
      - copied from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/jcr2spi/
      - copied from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/jcr2spi/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/jcr2spi/default-nodetypes.cnd
      - copied unchanged from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/resources/org/apache/jackrabbit/jcr2spi/default-nodetypes.cnd
Modified:
    jackrabbit/trunk/   (props changed)
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java

Propchange: jackrabbit/trunk/
------------------------------------------------------------------------------
    svn:mergeinfo = /jackrabbit/branches/1.5:794012,794100,794102

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java?rev=794302&r1=794301&r2=794302&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateFactory.java
Wed Jul 15 15:37:59 2009
@@ -217,13 +217,16 @@
         }
 
         // deal with all additional ItemInfos that may be present.
-        NodeEntry parentEntry = nodeState.getNodeEntry();
+        // 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 approxParentEntry = nodeState.getNodeEntry();
         while (infos.hasNext()) {
             ItemInfo info = (ItemInfo) infos.next();
             if (info.denotesNode()) {
-                createDeepNodeState((NodeInfo) info, parentEntry, infos);
+                approxParentEntry = createDeepNodeState((NodeInfo) info, approxParentEntry,
infos).getNodeEntry();
             } else {
-                createDeepPropertyState((PropertyInfo) info, parentEntry, infos);
+                createDeepPropertyState((PropertyInfo) info, approxParentEntry, infos);
             }
         }
         return nodeState;
@@ -359,9 +362,18 @@
 
             NodeEntry entry = anyParent;
             for (int i = 0; i < missingElems.length; i++) {
-                Name name = missingElems[i].getName();
-                int index = missingElems[i].getNormalizedIndex();
-                entry = createIntermediateNodeEntry(entry, name, index, infos);
+                if (missingElems[i].denotesParent()) {
+                    // Walk up the hierarchy for 'negative' paths
+                    // until the smallest common root is found
+                    entry = entry.getParent();
+                }
+                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");
@@ -400,9 +412,18 @@
             int i = 0;
             // NodeEntries except for the very last 'missingElem'
             while (i < missingElems.length - 1) {
-                Name name = missingElems[i].getName();
-                int index = missingElems[i].getNormalizedIndex();
-                entry = createIntermediateNodeEntry(entry, name, index, infos);
+                if (missingElems[i].denotesParent()) {
+                    // Walk up the hierarchy for 'negative' paths
+                    // until the smallest common root is found
+                    entry = entry.getParent();
+                }
+                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
@@ -473,8 +494,8 @@
     }
 
     /**
-     * Returns true if the given <code>missingElems</code> start with a parent
(..),
-     * a current (.) or the root element, in which case the info is not within
+     * Returns true if the given <code>missingElems</code> start with
+     * 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.
      *
@@ -483,7 +504,7 @@
      */
     private static boolean startsWithIllegalElement(Path.Element[] missingElems) {
         if (missingElems.length > 0) {
-            return !missingElems[0].denotesName();
+            return missingElems[0].denotesRoot();
         }
         return false;
     }

Copied: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
(from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java?p2=jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java&p1=jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java&r1=794012&r2=794302&rev=794302&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/AbstractJCR2SPITest.java
Wed Jul 15 15:37:59 2009
@@ -16,22 +16,34 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
+import java.io.BufferedInputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Credentials;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 
 import junit.framework.TestCase;
 
 import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
 import org.apache.jackrabbit.spi.Batch;
+import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.EventBundle;
 import org.apache.jackrabbit.spi.EventFilter;
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.ItemInfo;
 import org.apache.jackrabbit.spi.LockInfo;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NameFactory;
@@ -42,23 +54,28 @@
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.PropertyInfo;
 import org.apache.jackrabbit.spi.QNodeDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.Subscription;
+import org.apache.jackrabbit.spi.commons.AbstractReadableRepositoryService;
+import org.apache.jackrabbit.spi.commons.nodetype.compact.ParseException;
 
 /**
  * Abstract base class for jcr2spi tests. This class implements {@link RepositoryService}
- * by delegation to {@link AbstractRepositoryService}. Implementors can overrid individual
- * methods as needed.
+ * by delegation to {@link AbstractReadableRepositoryService}. Implementors can override
+ * individual methods as needed.
  */
 public abstract class AbstractJCR2SPITest extends TestCase implements RepositoryService {
     protected RepositoryService repositoryService;
     protected RepositoryConfig config;
     protected Repository repository;
 
+    @Override
     public void setUp() throws Exception {
         super.setUp();
         repositoryService = getRepositoryService();
@@ -66,28 +83,93 @@
         repository = getRepository();
     }
 
-    protected RepositoryService getRepositoryService() throws RepositoryException {
-        return new AbstractRepositoryService() {
-            public Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId)
-                    throws RepositoryException {
+    protected RepositoryService getRepositoryService() throws RepositoryException, ParseException
{
+        return new AbstractReadableRepositoryService(getDescriptors(), getNameSpaces(), getCndReader(),
+                getWspNames()) {
+
+            @Override
+            protected void checkCredentials(Credentials credentials, String workspaceName)
+                    throws LoginException {
 
-                return AbstractJCR2SPITest.this.getChildInfos(sessionInfo, parentId);
+                // empty
+            }
+
+            @Override
+            protected QNodeDefinition createRootNodeDefinition() throws RepositoryException
{
+                // todo implement createRootNodeDefinition
+                return null;
             }
 
-            public Iterator getItemInfos(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException
{
+            @Override
+            public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo,
NodeId nodeId)
+                    throws ItemNotFoundException, RepositoryException {
+
                 return AbstractJCR2SPITest.this.getItemInfos(sessionInfo, nodeId);
             }
 
-            public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException
{
+            public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId
parentId)
+                    throws ItemNotFoundException, RepositoryException {
+
+                return AbstractJCR2SPITest.this.getChildInfos(sessionInfo, parentId);
+            }
+
+            public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException,
+                    RepositoryException {
+
                 return AbstractJCR2SPITest.this.getNodeInfo(sessionInfo, nodeId);
             }
 
-            public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId)
{
+            public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId)
+                    throws ItemNotFoundException, RepositoryException {
+
                 return AbstractJCR2SPITest.this.getPropertyInfo(sessionInfo, propertyId);
             }
+
+            public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId
nodeId,
+                    Name propertyName, boolean weakReferences) throws ItemNotFoundException,
+                    RepositoryException {
+
+                return AbstractJCR2SPITest.this.getReferences(sessionInfo, nodeId, propertyName,
weakReferences);
+            }
+
         };
     }
 
+    protected Reader getCndReader() throws RepositoryException {
+        String resourceName = "default-nodetypes.cnd";
+        InputStream is = AbstractJCR2SPITest.class.getResourceAsStream(resourceName);
+        if (is == null) {
+            throw new RepositoryException(("Resource not found: " + resourceName));
+        }
+
+        return new InputStreamReader(new BufferedInputStream(is));
+    }
+
+    protected Map<String, String> getNameSpaces() {
+        return Collections.emptyMap();
+    }
+
+    protected Map<String, String> getDescriptors() {
+        Map<String, String> descriptorKeys = new HashMap<String, String>();
+
+        descriptorKeys.put(Repository.OPTION_LOCKING_SUPPORTED, Boolean.FALSE.toString());
+        descriptorKeys.put(Repository.OPTION_OBSERVATION_SUPPORTED, Boolean.FALSE.toString());
+        descriptorKeys.put(Repository.OPTION_TRANSACTIONS_SUPPORTED, Boolean.FALSE.toString());
+        descriptorKeys.put(Repository.OPTION_VERSIONING_SUPPORTED, Boolean.FALSE.toString());
+        descriptorKeys.put(Repository.REP_NAME_DESC, "Mock Repository");
+        descriptorKeys.put(Repository.REP_VENDOR_DESC, "Apache Software Foundation");
+        descriptorKeys.put(Repository.REP_VENDOR_URL_DESC, "http://www.apache.org/");
+        descriptorKeys.put(Repository.REP_VERSION_DESC, "1.0");
+        descriptorKeys.put(Repository.SPEC_NAME_DESC, "Content Repository API for Java(TM)
Technology Specification");
+        descriptorKeys.put(Repository.SPEC_VERSION_DESC, "1.0");
+
+        return descriptorKeys;
+    }
+
+    protected List<String> getWspNames() {
+        return Collections.singletonList("default");
+    }
+
     protected RepositoryConfig getRepositoryConfig() {
         return new AbstractRepositoryConfig() {
             public RepositoryService getRepositoryService() throws RepositoryException {
@@ -118,7 +200,7 @@
         return repositoryService.getQValueFactory();
     }
 
-    public Map getRepositoryDescriptors() throws RepositoryException {
+    public Map<String, String> getRepositoryDescriptors() throws RepositoryException
{
         return repositoryService.getRepositoryDescriptors();
     }
 
@@ -173,9 +255,9 @@
 
     public abstract NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException;
 
-    public abstract Iterator getItemInfos(SessionInfo sessionInfo, NodeId nodeId) throws
RepositoryException;
+    public abstract Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo,
NodeId nodeId) throws ItemNotFoundException, RepositoryException;
 
-    public abstract Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws
RepositoryException;
+    public abstract Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId
parentId) throws ItemNotFoundException, RepositoryException;
 
     public abstract PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId);
 
@@ -282,8 +364,8 @@
         repositoryService.restore(sessionInfo, nodeId, versionId, removeExisting);
     }
 
-    public Iterator merge(SessionInfo sessionInfo, NodeId nodeId, String srcWorkspaceName,
boolean bestEffort)
-            throws RepositoryException {
+    public Iterator<NodeId> merge(SessionInfo sessionInfo, NodeId nodeId, String srcWorkspaceName,
+            boolean bestEffort) throws RepositoryException {
 
         return repositoryService.merge(sessionInfo, nodeId, srcWorkspaceName, bestEffort);
     }
@@ -314,16 +396,18 @@
     }
 
 
-    public void checkQueryStatement(SessionInfo sessionInfo, String statement, String language,
-            Map namespaces) throws RepositoryException {
+    public String[] checkQueryStatement(SessionInfo sessionInfo, String statement, String
language,
+            Map<String, String> namespaces) throws RepositoryException {
 
-        repositoryService.checkQueryStatement(sessionInfo, statement, language, namespaces);
+        return repositoryService.checkQueryStatement(sessionInfo, statement, language, namespaces);
     }
 
     public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language,
-            Map namespaces) throws RepositoryException {
+            Map<String, String> namespaces, long limit, long offset, Map<String,
QValue> values)
+            throws RepositoryException {
 
-        return repositoryService.executeQuery(sessionInfo, statement, language, namespaces);
+        return repositoryService.executeQuery(sessionInfo, statement, language, namespaces,
limit, offset,
+                values);
     }
 
 
@@ -360,7 +444,7 @@
 
     //---------------------------------------------------------< Namespaces >---
 
-    public Map getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException
{
+    public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws
RepositoryException {
         return repositoryService.getRegisteredNamespaces(sessionInfo);
     }
 
@@ -389,14 +473,97 @@
 
     //----------------------------------------------------------< NodeTypes >---
 
-    public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo) throws RepositoryException
{
+    public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo)
+            throws RepositoryException {
+
         return repositoryService.getQNodeTypeDefinitions(sessionInfo);
     }
 
-    public Iterator getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodeTypeNames)
+    public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo,
Name[] nodeTypeNames)
             throws RepositoryException {
 
         return repositoryService.getQNodeTypeDefinitions(sessionInfo, nodeTypeNames);
     }
 
+    public NodeId checkpoint(SessionInfo sessionInfo, NodeId nodeId)
+            throws RepositoryException {
+
+        return repositoryService.checkpoint(sessionInfo, nodeId);
+    }
+
+    public NodeId createActivity(SessionInfo sessionInfo, String title)
+            throws RepositoryException {
+
+        return repositoryService.createActivity(sessionInfo, title);
+    }
+
+    public NodeId createConfiguration(SessionInfo sessionInfo, NodeId nodeId, NodeId baselineId)
+            throws RepositoryException {
+
+        return repositoryService.createConfiguration(sessionInfo, nodeId, baselineId);
+    }
+
+    public void createWorkspace(SessionInfo sessionInfo, String name, String srcWorkspaceName)
+            throws RepositoryException {
+
+        repositoryService.createWorkspace(sessionInfo, name, srcWorkspaceName);
+    }
+
+    public void deleteWorkspace(SessionInfo sessionInfo, String name) throws RepositoryException
{
+        repositoryService.deleteWorkspace(sessionInfo, name);
+    }
+
+    public EventBundle getEvents(SessionInfo sessionInfo, EventFilter filter, long after)
+            throws RepositoryException {
+
+        return repositoryService.getEvents(sessionInfo, filter, after);
+    }
+
+    public Iterator<PropertyId> getReferences(SessionInfo sessionInfo, NodeId nodeId,
Name propertyName,
+            boolean weakReferences) throws RepositoryException {
+
+        return getReferences(sessionInfo, nodeId, propertyName, weakReferences);
+    }
+
+    public LockInfo lock(SessionInfo sessionInfo, NodeId nodeId, boolean deep, boolean sessionScoped,
+            long timeoutHint, String ownerHint) throws RepositoryException {
+
+        return repositoryService.lock(sessionInfo, nodeId, deep, sessionScoped, timeoutHint,
ownerHint);
+    }
+
+    public Iterator<NodeId> merge(SessionInfo sessionInfo, NodeId nodeId, String srcWorkspaceName,
+            boolean bestEffort, boolean isShallow) throws RepositoryException {
+
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public Iterator mergeActivity(SessionInfo sessionInfo, NodeId activityId)
+            throws RepositoryException {
+
+        return repositoryService.mergeActivity(sessionInfo, activityId);
+    }
+
+    public void registerNodeTypes(SessionInfo sessionInfo, QNodeTypeDefinition[] nodeTypeDefinitions,
+            boolean allowUpdate) throws RepositoryException {
+
+        repositoryService.registerNodeTypes(sessionInfo, nodeTypeDefinitions, allowUpdate);
+    }
+
+    public void removeActivity(SessionInfo sessionInfo, NodeId activityId)
+            throws RepositoryException {
+
+        repositoryService.removeActivity(sessionInfo, activityId);
+    }
+
+    public void unregisterNodeTypes(SessionInfo sessionInfo, Name[] nodeTypeNames)
+            throws UnsupportedRepositoryOperationException, NoSuchNodeTypeException, RepositoryException
{
+
+        repositoryService.unregisterNodeTypes(sessionInfo, nodeTypeNames);
+    }
+
 }
+
+
+
+

Copied: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
(from r794012, jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java?p2=jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java&p1=jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java&r1=794012&r2=794302&rev=794302&view=diff
==============================================================================
--- jackrabbit/branches/1.5/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
Wed Jul 15 15:37:59 2009
@@ -1,3 +1,19 @@
+/*
+ * 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.jcr2spi;
 
 import java.util.ArrayList;
@@ -20,6 +36,7 @@
 import org.apache.commons.collections.iterators.FilterIterator;
 import org.apache.commons.collections.iterators.IteratorChain;
 import org.apache.commons.collections.iterators.TransformIterator;
+import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.ItemInfo;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
@@ -45,12 +62,13 @@
  * for JCR-1797.
  */
 public class GetItemsTest extends AbstractJCR2SPITest {
-    private List itemInfos;
+    private List<ItemInfo> itemInfos;
     private Session session;
 
+    @Override
     public void setUp() throws Exception {
         super.setUp();
-        itemInfos = new ArrayList();
+        itemInfos = new ArrayList<ItemInfo>();
 
         // build up a hierarchy of items
         new NodeInfoBuilder()
@@ -77,45 +95,30 @@
             .createNodeInfo("node3").build(itemInfos)
             .build(itemInfos);
 
-        session = repository.login();
+        session = repository.login("default");
     }
 
     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();
-                    }
-                };
-
+            @SuppressWarnings("unchecked")
+            public Iterator<ItemInfo> iterator() {
                 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,35 +127,37 @@
     }
 
     /**
-     * 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 {
-        itemInfosProvider = new Iterable() {
+    public void testGetItemInfosDeepFirst() throws RepositoryException {
+        final String targetPath = "/node2/node21/node211/node2111/node21111/node211111/node2111111";
 
-            public Iterator iterator() {
-                Predicate isRoot = new Predicate() {
-                    public boolean evaluate(Object object) {
-                        ItemInfo itemInfo = (ItemInfo) object;
-                        return itemInfo.getPath().denotesRoot();
-                    }
-                };
+        itemInfosProvider = new Iterable() {
+            Predicate isTarget = new Predicate() {
+                public boolean evaluate(Object object) {
+                    ItemInfo itemInfo = (ItemInfo) object;
+                    return targetPath.equals(toJCRPath(itemInfo.getPath()));
+                }
+            };
 
+            @SuppressWarnings("unchecked")
+            public Iterator<ItemInfo> iterator() {
                 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();
     }
 
     private void checkHierarchy() throws PathNotFoundException, RepositoryException, ItemNotFoundException,
             AccessDeniedException {
-        for (Iterator itemInfos = itemInfosProvider.iterator(); itemInfos.hasNext();) {
-            ItemInfo itemInfo = (ItemInfo) itemInfos.next();
+        for (Iterator<ItemInfo> itemInfos = itemInfosProvider.iterator(); itemInfos.hasNext();)
{
+            ItemInfo itemInfo = itemInfos.next();
             String jcrPath = toJCRPath(itemInfo.getPath());
             Item item = session.getItem(jcrPath);
             assertEquals(jcrPath, item.getPath());
@@ -184,27 +189,33 @@
         return jcrPath.toString();
     }
 
-    public Iterator getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws RepositoryException
{
+    @Override
+    public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId)
+            throws RepositoryException {
+
         fail("Not implemented");
         return null;
     }
 
-    public Iterator getItemInfos(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException
{
+    @Override
+    public Iterator<ItemInfo> getItemInfos(SessionInfo sessionInfo, NodeId nodeId)
throws RepositoryException {
         return itemInfosProvider.iterator();
     }
 
+    @Override
     public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException
{
         fail("Not implemented");
         return null;
     }
 
+    @Override
     public PropertyInfo getPropertyInfo(SessionInfo sessionInfo, PropertyId propertyId) {
         fail("Not implemented");
         return null;
     }
 
     interface Iterable {
-        public Iterator iterator();
+        public Iterator<ItemInfo> iterator();
     }
 
     /**
@@ -215,7 +226,7 @@
         private final String name;
 
         protected boolean stale;
-        private final List itemInfos = new ArrayList();
+        private final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
         private NodeInfo nodeInfo;
 
         public NodeInfoBuilder() {
@@ -236,7 +247,8 @@
             return new NodeInfoBuilder(this, name);
         }
 
-        public NodeInfoBuilder build(List infos) throws RepositoryException {
+        @SuppressWarnings("unchecked")
+        public NodeInfoBuilder build(List<ItemInfo> infos) throws RepositoryException
{
             if (stale) {
                 throw new IllegalStateException("Builder is stale");
             }
@@ -246,7 +258,7 @@
                 NodeId id = getId();
                 Path path = id.getPath();
 
-                Iterator propertyIds = new TransformIterator(new FilterIterator(itemInfos.iterator(),
+                Iterator<ItemInfo> propertyIds = new TransformIterator(new FilterIterator(itemInfos.iterator(),
                         new Predicate() {
                             public boolean evaluate(Object object) {
                                 return object instanceof PropertyInfo;
@@ -258,7 +270,7 @@
                                 return info.getId();
                             }});
 
-                Iterator childInfos = new TransformIterator(itemInfos.iterator(), new Transformer(){
+                Iterator<ItemInfo> childInfos = new TransformIterator(itemInfos.iterator(),
new Transformer(){
                     public Object transform(Object input) {
                         ItemInfo info = (ItemInfo) input;
                         Name name = info.getPath().getNameElement().getName();
@@ -333,7 +345,7 @@
             this.value = value;
         }
 
-        public NodeInfoBuilder build(List infos) throws RepositoryException {
+        public NodeInfoBuilder build(List<ItemInfo> infos) throws RepositoryException
{
             if (parent == null) {
                 return null;
             }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java?rev=794302&r1=794301&r2=794302&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
Wed Jul 15 15:37:59 2009
@@ -19,6 +19,7 @@
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,6 +35,7 @@
         TestSuite suite = new TestSuite("jcr2spi tests");
 
         suite.addTestSuite(AccessByRelativePathTest.class);
+        suite.addTestSuite(GetItemsTest.class);
 
         // get node(s)
         suite.addTestSuite(SNSIndexTest.class);
@@ -85,7 +87,7 @@
         suite.addTestSuite(ReorderNewAndSavedTest.class);
         suite.addTestSuite(ReorderMixedTest.class);
         suite.addTestSuite(ReorderMoveTest.class);
-        
+
         // update
         suite.addTestSuite(UpdateTest.class);
 
@@ -98,7 +100,7 @@
 
         // repository
         suite.addTestSuite(LoginTest.class);
-        
+
         return suite;
     }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=794302&r1=794301&r2=794302&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Wed Jul 15 15:37:59 2009
@@ -266,8 +266,7 @@
      * 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.
+     * arbitrary <code>ItemInfo</code>s.
      *
      * @param sessionInfo
      * @param nodeId
@@ -275,8 +274,7 @@
      * at least a single element: the <code>NodeInfo</code> that represents
      * 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>.
+     * identified by the given <code>NodeId</code>.
      * @throws javax.jcr.ItemNotFoundException
      * @throws javax.jcr.RepositoryException
      * @see javax.jcr.Session#getItem(String)



Mime
View raw message