Search in sources :

Example 1 with NodeIterator

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

the class AutoFixCorruptNode method testAutoFix.

public void testAutoFix() throws Exception {
    // new repository
    TransientRepository rep = new TransientRepository(new File(TEST_DIR));
    Session s = openSession(rep, false);
    Node root = s.getRootNode();
    // add nodes /test and /test/missing
    Node test = root.addNode("test");
    Node missing = test.addNode("missing");
    missing.addMixin("mix:referenceable");
    UUID id = UUID.fromString(missing.getIdentifier());
    s.save();
    s.logout();
    destroyBundle(id, "workspaces/default");
    // login and try the operation
    s = openSession(rep, false);
    test = s.getRootNode().getNode("test");
    // try to add a node with the same name
    try {
        test.addNode("missing");
        s.save();
    } catch (RepositoryException e) {
    // expected
    }
    s.logout();
    s = openSession(rep, true);
    test = s.getRootNode().getNode("test");
    // iterate over all child nodes fixes the corruption
    NodeIterator it = test.getNodes();
    while (it.hasNext()) {
        it.nextNode();
    }
    // try to add a node with the same name
    test.addNode("missing");
    s.save();
    // try to delete the parent node
    test.remove();
    s.save();
    s.logout();
    rep.shutdown();
    FileUtils.deleteDirectory(new File("repository"));
}
Also used : NodeIterator(javax.jcr.NodeIterator) TransientRepository(org.apache.jackrabbit.core.TransientRepository) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) UUID(java.util.UUID) File(java.io.File) Session(javax.jcr.Session)

Example 2 with NodeIterator

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

the class LazyResultSetQueryTest 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) {
            testRootNode.getSession().save();
        }
    }
    testRootNode.getSession().save();
    super.tearDown();
}
Also used : NodeIterator(javax.jcr.NodeIterator)

Example 3 with NodeIterator

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

the class DerefTest method testDerefToVersionNode.

/**
     * Checks if jcr:deref works when dereferencing into the version storage.
     */
public void testDerefToVersionNode() throws RepositoryException {
    Node referenced = testRootNode.addNode(nodeName1);
    referenced.addMixin(mixVersionable);
    testRootNode.save();
    Version version = referenced.checkin();
    Node referencedVersionNode = version.getNode(jcrFrozenNode);
    Node referencer = testRootNode.addNode(nodeName2);
    referencer.setProperty(propertyName1, referencedVersionNode);
    testRootNode.save();
    String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    Query q = qm.createQuery(query, Query.XPATH);
    QueryResult qr = q.execute();
    NodeIterator ni = qr.getNodes();
    assertEquals("Must find one result in query", 1, ni.getSize());
    while (ni.hasNext()) {
        Node node = (Node) ni.next();
        assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Version(javax.jcr.version.Version) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 4 with NodeIterator

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

the class LimitAndOffsetTest method testOffsetAndLimitWithGetSize.

public void testOffsetAndLimitWithGetSize() throws Exception {
    query.setOffset(1);
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    assertEquals(2, nodes.getSize());
    if (result instanceof JackrabbitQueryResult) {
        assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
    }
    // JCR-2684: offset higher than total result => size == 0
    query.setOffset(10);
    result = query.execute();
    nodes = result.getNodes();
    assertFalse(nodes.hasNext());
    assertEquals(0, nodes.getSize());
    if (result instanceof JackrabbitQueryResult) {
        assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
    }
    query.setOffset(1);
    query.setLimit(1);
    result = query.execute();
    nodes = result.getNodes();
    assertEquals(1, nodes.getSize());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 5 with NodeIterator

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

the class LimitAndOffsetTest method testOffsetAndSkip.

public void testOffsetAndSkip() throws Exception {
    query.setOffset(1);
    QueryResult result = query.execute();
    NodeIterator nodes = result.getNodes();
    nodes.skip(1);
    assertTrue(node3.isSame(nodes.nextNode()));
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

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