Search in sources :

Example 21 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit by apache.

the class QueryResultTest method testGetSize.

public void testGetSize() throws RepositoryException {
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    for (int i = 0; i < 10; i++) {
        String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
        QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
        assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
        // remove node for the next iteration
        testRootNode.getNode("node" + i).remove();
        testRootNode.save();
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager)

Example 22 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit by apache.

the class QueryResultTest method testGetSizeOrderByScore.

public void testGetSizeOrderByScore() throws RepositoryException {
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    for (int i = 0; i < 10; i++) {
        String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
        QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
        assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
        // remove node for the next iteration
        testRootNode.getNode("node" + i).remove();
        testRootNode.save();
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager)

Example 23 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit by apache.

the class QueryResultTest method testGetPosition.

public void testGetPosition() throws RepositoryException {
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    for (int i = 0; i < 10; i++) {
        String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
        QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
        NodeIterator it = result.getNodes();
        assertEquals("Wrong position", 0, it.getPosition());
        int count = 0;
        while (it.hasNext()) {
            long position = it.getPosition();
            it.nextNode();
            assertEquals("Wrong position", count++, position);
        }
        try {
            it.next();
            fail("must throw NoSuchElementException");
        } catch (Exception e) {
        // correct
        }
        // remove node for the next iteration
        testRootNode.getNode("node" + i).remove();
        testRootNode.save();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) NoSuchElementException(java.util.NoSuchElementException)

Example 24 with QueryManager

use of javax.jcr.query.QueryManager in project jackrabbit by apache.

the class QueryResultTest method testIteratorNextOrderByScore.

public void testIteratorNextOrderByScore() throws RepositoryException {
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    for (int i = 0; i < 10; i++) {
        String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
        QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
        int size = 0;
        for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
            it.nextNode();
            size++;
        }
        assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, size);
        // remove node for the next iteration
        testRootNode.getNode("node" + i).remove();
        testRootNode.save();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager)

Example 25 with QueryManager

use of javax.jcr.query.QueryManager 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)

Aggregations

QueryManager (javax.jcr.query.QueryManager)103 Query (javax.jcr.query.Query)69 Node (javax.jcr.Node)61 QueryResult (javax.jcr.query.QueryResult)55 Session (javax.jcr.Session)54 NodeIterator (javax.jcr.NodeIterator)34 RowIterator (javax.jcr.query.RowIterator)27 Test (org.junit.Test)27 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)22 RepositoryException (javax.jcr.RepositoryException)18 Row (javax.jcr.query.Row)14 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)14 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 ValueFactory (javax.jcr.ValueFactory)7 NoSuchElementException (java.util.NoSuchElementException)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 Value (javax.jcr.Value)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2