Search in sources :

Example 31 with RowIterator

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

the class QueryTest method propertyIndexWithDeclaringNodeTypeAndRelativQuery.

@Test
public void propertyIndexWithDeclaringNodeTypeAndRelativQuery() throws RepositoryException {
    Session session = getAdminSession();
    RowIterator rit;
    QueryResult r;
    String query;
    query = "//element(*, rep:Authorizable)[@rep:principalName = 'admin']";
    r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
    rit = r.getRows();
    assertEquals("[rep:Authorizable] as [a] /* property principalName = admin " + "where [a].[rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
    query = "//element(*, rep:Authorizable)[admin/@rep:principalName = 'admin']";
    r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
    rit = r.getRows();
    assertEquals("[rep:Authorizable] as [a] /* nodeType " + "Filter(query=explain select [jcr:path], [jcr:score], * " + "from [rep:Authorizable] as a " + "where [admin/rep:principalName] = 'admin' " + "/* xpath: //element(*, rep:Authorizable)[" + "admin/@rep:principalName = 'admin'] */, path=*, " + "property=[admin/rep:principalName=[admin]]) " + "where [a].[admin/rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 32 with RowIterator

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

the class QueryPlanTest method uuidIndex.

@Test
public void uuidIndex() throws Exception {
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node testRootNode = session.getRootNode().addNode("testroot");
    Node n = testRootNode.addNode("node");
    n.addMixin("mix:referenceable");
    session.save();
    // this matches just one node (exact path),
    // so it should use the TraversintIndex
    String xpath = "/jcr:root/testroot/node[@jcr:uuid]";
    Query q;
    QueryResult result;
    RowIterator it;
    q = qm.createQuery("explain " + xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String plan = it.nextRow().getValue("plan").getString();
    assertEquals("[nt:base] as [a] /* traverse \"/testroot/node\" where " + "([a].[jcr:uuid] is not null) " + "and (issamenode([a], [/testroot/node])) */", plan);
    // verify the result
    q = qm.createQuery(xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String path = it.nextRow().getPath();
    assertEquals("/testroot/node", path);
    assertFalse(it.hasNext());
    // this potentially matches many nodes,
    // so it should use the index on the UUID property
    xpath = "/jcr:root/testroot/*[@jcr:uuid]";
    q = qm.createQuery("explain " + xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    plan = it.nextRow().getValue("plan").getString();
    assertEquals("[nt:base] as [a] /* property uuid IS NOT NULL " + "where ([a].[jcr:uuid] is not null) " + "and (ischildnode([a], [/testroot])) */", plan);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 33 with RowIterator

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

the class QueryPlanTest method nodeType.

@Test
public void nodeType() throws Exception {
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node nodetype = session.getRootNode().getNode("oak:index").getNode("nodetype");
    nodetype.setProperty("entryCount", 10000000);
    Node testRootNode = session.getRootNode().addNode("testroot");
    Node n1 = testRootNode.addNode("node1");
    Node n2 = n1.addNode("node2");
    n2.addNode("node3");
    session.save();
    String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where [node2/node3/jcr:primaryType] is not null " + "and isdescendantnode('/testroot')";
    Query q;
    QueryResult result;
    RowIterator it;
    q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String plan = it.nextRow().getValue("plan").getString();
    // should not use the index on "jcr:primaryType"
    assertEquals("[nt:base] as [nt:base] /* traverse \"/testroot//*\" " + "where ([nt:base].[node2/node3/jcr:primaryType] is not null) " + "and (isdescendantnode([nt:base], [/testroot])) " + "*/", plan);
    // verify the result
    q = qm.createQuery(sql2, Query.JCR_SQL2);
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String path = it.nextRow().getValue("path").getString();
    assertEquals("/testroot/node1", path);
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Session(javax.jcr.Session) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 34 with RowIterator

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

the class LuceneIndexDescendantSpellcheckTest method getSpellchecks.

private Set<String> getSpellchecks(String query) throws Exception {
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(query, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    Set<String> suggestions = newHashSet();
    while (rows.hasNext()) {
        suggestions.add(rows.nextRow().getValue("spellcheck").getString());
    }
    return suggestions;
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager)

Example 35 with RowIterator

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

the class SpellcheckTest method getResult.

static List<String> getResult(QueryResult result, String propertyName) throws RepositoryException {
    List<String> results = Lists.newArrayList();
    RowIterator it = result.getRows();
    while (it.hasNext()) {
        Row row = it.nextRow();
        results.add(row.getValue(propertyName).getString());
    }
    return results;
}
Also used : RowIterator(javax.jcr.query.RowIterator) Row(javax.jcr.query.Row)

Aggregations

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3