Search in sources :

Example 71 with QueryResult

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

the class LimitAndOffsetTest method testOffsetAndLimit.

public void testOffsetAndLimit() throws Exception {
    query.setOffset(0);
    query.setLimit(1);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1 });
    query.setOffset(1);
    query.setLimit(1);
    result = query.execute();
    checkResult(result, new Node[] { node2 });
    query.setOffset(1);
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node2, node3 });
    query.setOffset(0);
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2 });
    // Added for JCR-1323
    query.setOffset(0);
    query.setLimit(4);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 72 with QueryResult

use of javax.jcr.query.QueryResult 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 73 with QueryResult

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

Example 74 with QueryResult

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

the class LimitAndOffsetTest method testOffset.

public void testOffset() throws Exception {
    query.setOffset(0);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
    query.setOffset(1);
    result = query.execute();
    checkResult(result, new Node[] { node2, node3 });
    query.setOffset(2);
    result = query.execute();
    checkResult(result, new Node[] { node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

Example 75 with QueryResult

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

the class LimitAndOffsetTest method testLimit.

public void testLimit() throws Exception {
    query.setLimit(1);
    QueryResult result = query.execute();
    checkResult(result, new Node[] { node1 });
    query.setLimit(2);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2 });
    query.setLimit(3);
    result = query.execute();
    checkResult(result, new Node[] { node1, node2, node3 });
}
Also used : QueryResult(javax.jcr.query.QueryResult) JackrabbitQueryResult(org.apache.jackrabbit.api.query.JackrabbitQueryResult)

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