Search in sources :

Example 21 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)

Example 22 with QueryResult

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

the class FullTextSearchTest method runTest.

@SuppressWarnings("deprecation")
@Override
protected void runTest(TestContext ec) throws Exception {
    QueryManager qm = ec.session.getWorkspace().getQueryManager();
    // like > 20% of the perf lost in Collections.sort
    for (String word : ec.words) {
        Query q = qm.createQuery("//*[jcr:contains(@text, '" + word + "')] ", Query.XPATH);
        QueryResult r = q.execute();
        RowIterator it = r.getRows();
        for (int rows = 0; it.hasNext() && rows < maxRowsToFetch; rows++) {
            Node n = it.nextRow().getNode();
            ec.hash += n.getProperty("text").getString().hashCode();
            ec.hash += n.getProperty("title").getString().hashCode();
        }
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 23 with QueryResult

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

the class MassiveRangeTest method testRangeQuery.

/**
     * Executes a range query covering 2'000 different property values.
     */
public void testRangeQuery() throws RepositoryException {
    int count = 0;
    for (int i = 0; i < 20; i++) {
        Node child = testRootNode.addNode("node" + i);
        for (int j = 0; j < 100; j++) {
            Node n = child.addNode("node" + j);
            n.setProperty("foo", count++);
        }
        // save every 100 nodes
        testRootNode.save();
    }
    QueryManager qm = superuser.getWorkspace().getQueryManager();
    String stmt = testPath + "//*[@foo >= 0]";
    QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
    checkResult(res, 2000);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager)

Example 24 with QueryResult

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

the class FacetResultTest method testResult.

@Test
public void testResult() throws Exception {
    QueryResult queryResult = mock(QueryResult.class);
    when(queryResult.getColumnNames()).thenReturn(new String[] { "rep:facet(text)", "jcr:path", "rep:facet(jcr:title)" });
    RowIterator rows = mock(RowIterator.class);
    when(rows.hasNext()).thenReturn(true);
    Row row = mock(Row.class);
    Value value = mock(Value.class);
    when(value.getString()).thenReturn("{}");
    when(row.getValue("rep:facet(text)")).thenReturn(value);
    Value value2 = mock(Value.class);
    when(value2.getString()).thenReturn("{\"a\" : 2, \"b\" : 1}");
    when(row.getValue("rep:facet(jcr:title)")).thenReturn(value2);
    when(rows.nextRow()).thenReturn(row);
    when(queryResult.getRows()).thenReturn(rows);
    FacetResult facetResult = new FacetResult(queryResult);
    assertNotNull(facetResult.getDimensions());
    assertEquals(2, facetResult.getDimensions().size());
    assertTrue(facetResult.getDimensions().contains("text"));
    assertTrue(facetResult.getDimensions().contains("jcr:title"));
    assertNotNull(facetResult.getFacets("text"));
    assertTrue(facetResult.getFacets("text").isEmpty());
    assertNotNull(facetResult.getFacets("jcr:title"));
    assertEquals(2, facetResult.getFacets("jcr:title").size());
    assertEquals("a", facetResult.getFacets("jcr:title").get(0).getLabel());
    assertEquals(2, facetResult.getFacets("jcr:title").get(0).getCount(), 0);
    assertEquals("b", facetResult.getFacets("jcr:title").get(1).getLabel());
    assertEquals(1, facetResult.getFacets("jcr:title").get(1).getCount(), 0);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) Row(javax.jcr.query.Row) Test(org.junit.Test)

Example 25 with QueryResult

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

the class XPathDocOrderTest method docOrderTest.

//-----------------------------< internal >---------------------------------
/**
     * Executes a statement, checks if the Result contains exactly one node with
     * <code>path</code>.
     *
     * @param stmt to be executed
     * @param path the path of the node in the query result.
     */
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
    if (!isSupported(Repository.QUERY_XPATH_DOC_ORDER)) {
        throw new NotExecutableException("Repository does not support document order on result set.");
    }
    int count = 0;
    // check precondition: at least 3 nodes
    for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
        count++;
    }
    if (count < 3) {
        throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
    }
    QueryResult result = execute(stmt);
    checkResult(result, 1);
    assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
Also used : NodeIterator(javax.jcr.NodeIterator) QueryResult(javax.jcr.query.QueryResult) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Aggregations

QueryResult (javax.jcr.query.QueryResult)200 Node (javax.jcr.Node)108 Query (javax.jcr.query.Query)97 QueryManager (javax.jcr.query.QueryManager)54 NodeIterator (javax.jcr.NodeIterator)52 RowIterator (javax.jcr.query.RowIterator)46 Session (javax.jcr.Session)35 Test (org.junit.Test)32 Row (javax.jcr.query.Row)21 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)21 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)15 RepositoryException (javax.jcr.RepositoryException)14 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