Search in sources :

Example 81 with QueryResult

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

the class ExcerptTest method checkExcerpt.

private void checkExcerpt(String text, String fragmentText, String terms) throws RepositoryException {
    String excerpt = createExcerpt(fragmentText);
    createTestData(text);
    String stmt = getStatement(terms);
    QueryResult result = executeQuery(stmt);
    RowIterator rows = result.getRows();
    assertEquals(1, rows.getSize());
    assertEquals(excerpt, getExcerpt(rows.nextRow()));
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator)

Example 82 with QueryResult

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

the class SelectorTest method testSelector.

public void testSelector() throws RepositoryException {
    // make sure there's at least one node with this node type
    testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), null, null, null);
    forQOMandSQL2(qom, new Callable() {

        public Object call(Query query) throws RepositoryException {
            QueryResult result = query.execute();
            String[] names = result.getSelectorNames();
            assertNotNull(names);
            assertEquals(1, names.length);
            assertEquals("s", names[0]);
            NodeIterator it = result.getNodes();
            while (it.hasNext()) {
                assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
            }
            return null;
        }
    });
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) RepositoryException(javax.jcr.RepositoryException)

Example 83 with QueryResult

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

the class QueryTest method testSQL2Simple.

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

Example 84 with QueryResult

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

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

the class OrderedIndexQueryBaseTest method runTest.

@Override
protected void runTest() throws Exception {
    QueryManager qm = session.getWorkspace().getQueryManager();
    Query q = qm.createQuery(getQuery(), Query.JCR_SQL2);
    QueryResult r = q.execute();
    NodeIterator nodes = r.getNodes();
    int counter = 0;
    while (nodes.hasNext() && counter++ < FETCH_NODES) {
        nodes.next();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryManager(javax.jcr.query.QueryManager)

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