Search in sources :

Example 76 with NodeIterator

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

the class XATransaction method execute.

public NodeIterator execute() throws Exception {
    UserTransactionImpl tx = new UserTransactionImpl(getSession());
    log.info("begin transaction");
    tx.begin();
    NodeIterator it = op.execute();
    log.info("commit transaction");
    tx.commit();
    return it;
}
Also used : NodeIterator(javax.jcr.NodeIterator) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl)

Example 77 with NodeIterator

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

the class LargeResultSetTest method tearDown.

protected void tearDown() throws Exception {
    int count = 0;
    for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
        it.nextNode().remove();
        count++;
        if (count % 10000 == 0) {
            session.save();
        }
    }
    session.save();
    super.tearDown();
}
Also used : NodeIterator(javax.jcr.NodeIterator)

Example 78 with NodeIterator

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

the class Exporter method exportNodes.

/**
     * Called by {@link #exportNode(String, String, Node)} to recursively
     * call {@link #exportNode(String, String, Node)} for each child node.
     * Does nothing if this exporter is not recursive. 
     *
     * @param node parent node
     * @throws RepositoryException if a repository error occurs
     * @throws SAXException if a SAX error occurs
     */
protected void exportNodes(Node node) throws RepositoryException, SAXException {
    if (recurse && !share) {
        NodeIterator iterator = node.getNodes();
        while (iterator.hasNext()) {
            Node child = iterator.nextNode();
            exportNode(child);
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node)

Example 79 with NodeIterator

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

the class FilteringItemVisitor method visit.

/**
     * Called when the Visitor is passed to a <code>Node</code>.
     * <p>
     * It calls <code>TraversingItemVisitor.entering(Node, int)</code> followed by
     * <code>TraversingItemVisitor.leaving(Node, int)</code>. Implement these abstract methods to
     * specify behaviour on 'arrival at' and 'after leaving' the <code>Node</code>.
     * <p>
     * If this method throws, the visiting process is aborted.
     *
     * @param node the <code>Node</code> that is accepting this visitor.
     * @throws RepositoryException if an error occurrs
     */
public void visit(Node node) throws RepositoryException {
    if (this.traversalPredicate.evaluate(node)) {
        if (this.includePredicate == this.traversalPredicate || this.includePredicate.evaluate(node)) {
            try {
                if (!breadthFirst) {
                    // depth-first traversal
                    entering(node, currentLevel);
                    if (maxLevel == -1 || currentLevel < maxLevel) {
                        currentLevel++;
                        if (this.walkProperties) {
                            PropertyIterator propIter = node.getProperties();
                            while (propIter.hasNext()) {
                                propIter.nextProperty().accept(this);
                            }
                        }
                        NodeIterator nodeIter = node.getNodes();
                        while (nodeIter.hasNext()) {
                            nodeIter.nextNode().accept(this);
                        }
                        currentLevel--;
                    }
                    leaving(node, currentLevel);
                } else {
                    // breadth-first traversal
                    entering(node, currentLevel);
                    leaving(node, currentLevel);
                    if (maxLevel == -1 || currentLevel < maxLevel) {
                        if (this.walkProperties) {
                            PropertyIterator propIter = node.getProperties();
                            while (propIter.hasNext()) {
                                nextQueue.addLast(propIter.nextProperty());
                            }
                        }
                        NodeIterator nodeIter = node.getNodes();
                        while (nodeIter.hasNext()) {
                            nextQueue.addLast(nodeIter.nextNode());
                        }
                    }
                    while (!currentQueue.isEmpty() || !nextQueue.isEmpty()) {
                        if (currentQueue.isEmpty()) {
                            currentLevel++;
                            currentQueue = nextQueue;
                            nextQueue = new LinkedList();
                        }
                        Item e = (Item) currentQueue.removeFirst();
                        e.accept(this);
                    }
                    currentLevel = 0;
                }
            } catch (RepositoryException re) {
                currentLevel = 0;
                throw re;
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Item(javax.jcr.Item) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) LinkedList(java.util.LinkedList)

Example 80 with NodeIterator

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

the class ShareableNodeTest method testSearch.

/**
     * Verify that a descendant of a shareable node appears once in the
     * result set (6.13.23)
     */
public void testSearch() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    // add new referenceable child
    Node c = b1.addNode("c");
    ensureMixinType(c, mixReferenceable);
    b1.save();
    String sql = "SELECT * FROM nt:unstructured WHERE jcr:uuid = '" + c.getUUID() + "'";
    QueryResult res = workspace.getQueryManager().createQuery(sql, Query.SQL).execute();
    List<Node> list = new ArrayList<Node>();
    NodeIterator iter = res.getNodes();
    while (iter.hasNext()) {
        list.add(iter.nextNode());
    }
    assertEquals(1, list.size());
    assertTrue(list.get(0).isSame(c));
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Workspace(javax.jcr.Workspace)

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