Search in sources :

Example 36 with QueryResult

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

the class OrderByTest method testOrderByLowerCase.

public void testOrderByLowerCase() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("text", "Amundsen");
    n2.setProperty("text", "barents");
    n3.setProperty("text", "Wegener");
    testRootNode.save();
    String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by fn:lower-case(@text)";
    Query q = qm.createQuery(xpath, Query.XPATH);
    QueryResult result = q.execute();
    checkResult(result, new Node[] { n1, n2, n3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 37 with QueryResult

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

the class SkipDeletedNodesTest method testRemoveLastNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveLastNode() throws RepositoryException {
    testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the last node
    n3.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 38 with QueryResult

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

the class SkipDeletedNodesTest method testRemoveFirstNodeAfterHasNext.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     * </p>This test is different from the other tests that it removes the
     * node after another session has called hasNext() to retrieve the node
     * that gets deleted.
     */
public void testRemoveFirstNodeAfterHasNext() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    NodeIterator it = res.getNodes();
    it.hasNext();
    // now remove the first node
    n1.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    while (it.hasNext()) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 39 with QueryResult

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

the class SimpleQueryTest method testNegativeNumber.

public void testNegativeNumber() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("number", -10);
    Node bar = testRootNode.addNode("bar");
    bar.setProperty("number", -20);
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured WHERE number = -10";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 1);
    String xpath = "//*[@jcr:primaryType='nt:unstructured' and @number = -10]";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 1);
    sql = "SELECT * FROM nt:unstructured WHERE number <= -10";
    q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    result = q.execute();
    checkResult(result, 2);
    xpath = "//*[@jcr:primaryType='nt:unstructured' and @number <= -10]";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 2);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node)

Example 40 with QueryResult

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

the class SkipDeletedNodesTest method testRemoveSomeNode.

/**
     * Executes a query with one session and removes a node from that query
     * result with another session.
     */
public void testRemoveSomeNode() throws RepositoryException {
    testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    testRootNode.addNode("node3");
    testRootNode.save();
    // query the workspace for all three nodes
    String stmt = testPath + "/*";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    // now remove the second node
    n2.remove();
    testRootNode.save();
    // iterate over nodes
    int count = 0;
    log.println("Result nodes:");
    for (NodeIterator it = res.getNodes(); it.hasNext(); ) {
        assertEquals("Wrong value for getPosition().", count++, it.getPosition());
        try {
            log.println(it.nextNode().getPath());
        } catch (InvalidItemStateException e) {
            // this is allowed
            log.println("Invalid: <deleted>");
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Aggregations

QueryResult (javax.jcr.query.QueryResult)202 Node (javax.jcr.Node)109 Query (javax.jcr.query.Query)98 QueryManager (javax.jcr.query.QueryManager)55 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)36 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 RepositoryException (javax.jcr.RepositoryException)15 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 FacetResult (org.apache.jackrabbit.oak.query.facet.FacetResult)9 Value (javax.jcr.Value)8 NoSuchElementException (java.util.NoSuchElementException)7 ArrayList (java.util.ArrayList)6 ValueFactory (javax.jcr.ValueFactory)6 InvalidItemStateException (javax.jcr.InvalidItemStateException)5 JackrabbitQueryResult (org.apache.jackrabbit.api.query.JackrabbitQueryResult)5 TreeSet (java.util.TreeSet)4