Search in sources :

Example 16 with NodeIterator

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

the class RestoreTest method testRestoreOrder2Jcr2_3.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrder2Jcr2_3() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // reoder nodes
    versionManager.checkout(testRoot.getPath());
    testRoot.orderBefore(nodeName2, nodeName1);
    testRoot.getSession().save();
    versionManager.checkin(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(v1, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 17 with NodeIterator

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

the class RestoreTest method testRestoreOrderJcr2.

/**
     * Test the child ordering of restored nodes.
     * @throws RepositoryException
     */
public void testRestoreOrderJcr2() throws RepositoryException, NotExecutableException {
    // create a test-root that has orderable child nodes
    Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
    ensureMixinType(testRoot, mixVersionable);
    versionableNode.getSession().save();
    // create children of vNode and checkin
    Node child1 = testRoot.addNode(nodeName1);
    ensureMixinType(child1, mixVersionable);
    Node child2 = testRoot.addNode(nodeName2);
    ensureMixinType(child2, mixVersionable);
    testRoot.getSession().save();
    versionManager.checkin(child1.getPath());
    versionManager.checkin(child2.getPath());
    Version v1 = versionManager.checkin(testRoot.getPath());
    // remove node 1
    versionManager.checkout(testRoot.getPath());
    child1.remove();
    testRoot.getSession().save();
    versionManager.checkout(testRoot.getPath());
    // restore version 1.0
    versionManager.restore(v1, true);
    // check order
    NodeIterator iter = testRoot.getNodes();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n1 = iter.nextNode();
    assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
    Node n2 = iter.nextNode();
    String orderOk = nodeName1 + ", " + nodeName2;
    String order = n1.getName() + ", " + n2.getName();
    assertEquals("Invalid child node ordering", orderOk, order);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(javax.jcr.version.Version) Node(javax.jcr.Node)

Example 18 with NodeIterator

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

the class QueryTest method testQueryChildNodesOfRoot.

/**
     * Queries the child nodes of the root node.
     * @throws NotExecutableException 
     */
public void testQueryChildNodesOfRoot() throws RepositoryException, NotExecutableException {
    List<Node> nodes = new ArrayList<Node>();
    for (NodeIterator it = superuser.getRootNode().getNodes(); it.hasNext(); ) {
        nodes.add(it.nextNode());
    }
    Node[] children = nodes.toArray(new Node[nodes.size()]);
    executeXPathQuery(superuser, "/jcr:root/*", children);
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) ArrayList(java.util.ArrayList)

Example 19 with NodeIterator

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

the class QueryTest method testSQL2Limit.

/**
     * https://issues.apache.org/jira/browse/JCR-2543
     */
public void testSQL2Limit() throws Exception {
    Query q = qm.createQuery("SELECT * FROM [nt:unstructured]", Query.JCR_SQL2);
    q.setLimit(1);
    QueryResult r = q.execute();
    NodeIterator it = r.getNodes();
    assertTrue(it.hasNext());
    it.next();
    assertFalse(it.hasNext());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query)

Example 20 with NodeIterator

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

the class ClearWorkspace method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    Session s = CommandHelper.getSession(ctx);
    if (log.isDebugEnabled()) {
        log.debug("removing all content from workspace " + s.getWorkspace().getName());
    }
    // Set current node to root
    CommandHelper.setCurrentNode(ctx, s.getRootNode());
    NodeIterator iter = s.getRootNode().getNodes();
    while (iter.hasNext()) {
        Node n = (Node) iter.next();
        if (!n.getName().equals(JcrConstants.JCR_SYSTEM)) {
            n.remove();
        }
    }
    PropertyIterator pIter = s.getRootNode().getProperties();
    while (pIter.hasNext()) {
        Property p = pIter.nextProperty();
        if (!p.getName().equals(JcrConstants.JCR_PRIMARYTYPE)) {
            p.remove();
        }
    }
    return false;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Session(javax.jcr.Session)

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