Search in sources :

Example 96 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class AbstractOrderByTest method checkResultOrder.

/**
     * Checks if the node ordering in <code>result</code> is according to
     * <code>nodeNames</code>.
     * @param result the query result.
     * @param nodeNames the node names.
     */
protected void checkResultOrder(QueryResult result, String[] nodeNames) throws RepositoryException {
    List<Node> nodes = new ArrayList<Node>();
    for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
        nodes.add(it.nextNode());
    }
    assertEquals("Wrong hit count:", nodeNames.length, nodes.size());
    for (int i = 0; i < nodeNames.length; i++) {
        String name = nodes.get(i).getName();
        assertEquals("Wrong order of nodes:", nodeNames[i], name);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) ArrayList(java.util.ArrayList)

Example 97 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RepositoryServiceImpl method getChildInfos.

/**
     * {@inheritDoc}
     */
public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeIterator children = getNode(parentId, sInfo).getNodes();
    List<ChildInfo> childInfos = new ArrayList<ChildInfo>();
    try {
        while (children.hasNext()) {
            childInfos.add(new ChildInfoImpl(children.nextNode(), sInfo.getNamePathResolver()));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return childInfos.iterator();
}
Also used : NodeIterator(javax.jcr.NodeIterator) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ArrayList(java.util.ArrayList) ChildInfo(org.apache.jackrabbit.spi.ChildInfo) RepositoryException(javax.jcr.RepositoryException)

Example 98 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RepositoryServiceImpl method merge.

/**
     * {@inheritDoc}
     */
public Iterator<NodeId> merge(final SessionInfo sessionInfo, final NodeId nodeId, final String srcWorkspaceName, final boolean bestEffort) throws NoSuchWorkspaceException, AccessDeniedException, MergeException, LockException, InvalidItemStateException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    return (Iterator<NodeId>) executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            String nodePath = getNodePath(nodeId, sInfo);
            NodeIterator it = getVersionManager(sInfo).merge(nodePath, srcWorkspaceName, bestEffort);
            List<NodeId> ids = new ArrayList<NodeId>();
            while (it.hasNext()) {
                ids.add(idFactory.createNodeId(it.nextNode()));
            }
            return ids.iterator();
        }
    }, sInfo);
}
Also used : NodeIterator(javax.jcr.NodeIterator) NodeIterator(javax.jcr.NodeIterator) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyIterator(javax.jcr.PropertyIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.spi.NodeId)

Example 99 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit by apache.

the class RepositoryServiceImpl method mergeActivity.

/**
     * {@inheritDoc}
     */
public Iterator<NodeId> mergeActivity(SessionInfo sessionInfo, final NodeId activityId) throws UnsupportedRepositoryOperationException, RepositoryException {
    final SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    return (Iterator<NodeId>) executeWithLocalEvents(new Callable() {

        public Object run() throws RepositoryException {
            Node node = getNode(activityId, sInfo);
            NodeIterator it = getVersionManager(sInfo).merge(node);
            List<NodeId> ids = new ArrayList<NodeId>();
            while (it.hasNext()) {
                ids.add(idFactory.createNodeId(it.nextNode()));
            }
            return ids.iterator();
        }
    }, sInfo);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) NodeIterator(javax.jcr.NodeIterator) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) PropertyIterator(javax.jcr.PropertyIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeId(org.apache.jackrabbit.spi.NodeId)

Example 100 with NodeIterator

use of javax.jcr.NodeIterator in project jackrabbit-oak by apache.

the class SimpleSearchTest method runTest.

@Override
public void runTest() throws Exception {
    QueryManager manager = session.getWorkspace().getQueryManager();
    for (int i = 0; i < NODE_COUNT; i++) {
        Query query = createQuery(manager, i);
        NodeIterator iterator = query.execute().getNodes();
        while (iterator.hasNext()) {
            Node node = iterator.nextNode();
            if (node.getProperty("testcount").getLong() != i) {
                throw new Exception("Invalid test result: " + node.getPath());
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Aggregations

NodeIterator (javax.jcr.NodeIterator)307 Node (javax.jcr.Node)214 Session (javax.jcr.Session)55 QueryResult (javax.jcr.query.QueryResult)52 RepositoryException (javax.jcr.RepositoryException)40 Query (javax.jcr.query.Query)40 Test (org.junit.Test)36 QueryManager (javax.jcr.query.QueryManager)34 PropertyIterator (javax.jcr.PropertyIterator)30 ArrayList (java.util.ArrayList)26 Property (javax.jcr.Property)24 Version (javax.jcr.version.Version)23 NoSuchElementException (java.util.NoSuchElementException)19 Value (javax.jcr.Value)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)19 HashSet (java.util.HashSet)13 PathNotFoundException (javax.jcr.PathNotFoundException)12 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)11 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)11