Search in sources :

Example 61 with RowIterator

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

the class SplitOrderBySearcher method searchCommon.

protected void searchCommon(QueryManager qm, ExecutionContext context) throws RepositoryException {
    /** Execute standard query */
    Query stdQuery = getStandardQuery(qm, context);
    stdQuery.setLimit(LIMIT);
    QueryResult stdResult = stdQuery.execute();
    RowIterator stdIt = stdResult.getRows();
    // Iterate the standard shown first
    for (int rows = 0; stdIt.hasNext() && rows < LIMIT; rows++) {
        Node node = stdIt.nextRow().getNode();
        LOG.debug(node.getPath());
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node)

Example 62 with RowIterator

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

the class PaginationEnabledSearcher method iterate.

private Node iterate(Query query) throws RepositoryException {
    QueryResult r = query.execute();
    RowIterator it = r.getRows();
    Node last = null;
    while (it.hasNext()) {
        last = it.nextRow().getNode();
        LOG.debug(last.getPath());
    }
    return last;
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node)

Example 63 with RowIterator

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

the class QueryResultImpl method getRows.

@Override
public RowIterator getRows() throws RepositoryException {
    Iterator<RowImpl> rowIterator = new Iterator<RowImpl>() {

        private final Iterator<? extends ResultRow> it = result.getRows().iterator();

        private final String pathSelector;

        private RowImpl current;

        private int rowCount;

        //Avoid log check for every row access
        private final boolean debugEnabled = queryOpsLogger.isDebugEnabled();

        {
            String[] columnSelectorNames = result.getColumnSelectorNames();
            if (columnSelectorNames.length == 1) {
                pathSelector = columnSelectorNames[0];
            } else {
                pathSelector = null;
            }
            fetch();
        }

        private void fetch() {
            if (it.hasNext()) {
                current = new RowImpl(QueryResultImpl.this, it.next(), pathSelector);
                if (debugEnabled) {
                    rowCount++;
                    if (rowCount % 100 == 0) {
                        queryOpsLogger.debug("Iterated over [{}] results so far", rowCount);
                    }
                }
            } else {
                current = null;
            }
        }

        @Override
        public boolean hasNext() {
            return current != null;
        }

        @Override
        public RowImpl next() {
            if (current == null) {
                throw new NoSuchElementException();
            }
            RowImpl r = current;
            fetch();
            return r;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    final PrefetchIterator<RowImpl> prefIt = new PrefetchIterator<RowImpl>(sessionDelegate.sync(rowIterator), new PrefetchOptions() {

        {
            size = result.getSize();
            fastSize = sessionContext.getFastQueryResultSize();
            fastSizeCallback = result;
        }
    });
    return new RowIteratorAdapter(prefIt) {

        @Override
        public long getSize() {
            return prefIt.size();
        }
    };
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) RowIteratorAdapter(org.apache.jackrabbit.commons.iterator.RowIteratorAdapter) PrefetchOptions(org.apache.jackrabbit.oak.jcr.query.PrefetchIterator.PrefetchOptions) Iterator(java.util.Iterator) RowIterator(javax.jcr.query.RowIterator) NodeIterator(javax.jcr.NodeIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 64 with RowIterator

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

the class CompatibilityIssuesTest method testSearchDescendentUsingXPath.

@Test
public void testSearchDescendentUsingXPath() throws Exception {
    Session adminSession = getAdminSession();
    String testNodePath = "/home/users/geometrixx-outdoors/emily.andrews@mailinator.com/social/relationships/following/aaron.mcdonald@mailinator.com";
    Node testNode = JcrUtils.getOrCreateByPath(testNodePath, null, adminSession);
    testNode.setProperty("id", "aaron.mcdonald@mailinator.com");
    AccessControlManager acMgr = adminSession.getAccessControlManager();
    JackrabbitAccessControlList tmpl = AccessControlUtils.getAccessControlList(acMgr, "/home/users/geometrixx-outdoors");
    ValueFactory vf = adminSession.getValueFactory();
    Map<String, Value> restrictions = new HashMap<String, Value>();
    restrictions.put("rep:glob", vf.createValue("*/social/relationships/following/*"));
    tmpl.addEntry(EveryonePrincipal.getInstance(), new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ) }, true, restrictions);
    acMgr.setPolicy(tmpl.getPath(), tmpl);
    adminSession.save();
    Session anonymousSession = getRepository().login(new GuestCredentials());
    QueryManager qm = anonymousSession.getWorkspace().getQueryManager();
    Query q = qm.createQuery("/jcr:root/home//social/relationships/following//*[@id='aaron.mcdonald@mailinator.com']", Query.XPATH);
    QueryResult r = q.execute();
    RowIterator it = r.getRows();
    Assert.assertTrue(it.hasNext());
    anonymousSession.logout();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Query(javax.jcr.query.Query) HashMap(java.util.HashMap) Node(javax.jcr.Node) ValueFactory(javax.jcr.ValueFactory) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) QueryManager(javax.jcr.query.QueryManager) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Example 65 with RowIterator

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

the class QueryPlanTest method pathAndPropertyRestrictions.

@Test
@Ignore("OAK-1372")
public void pathAndPropertyRestrictions() throws Exception {
    // TODO work in progress
    ;
    Session session = getAdminSession();
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node testRootNode = session.getRootNode().addNode("testroot");
    Node b = testRootNode.addNode("b");
    Node c = b.addNode("c");
    Node d = c.addNode("d");
    Node e1 = d.addNode("e1");
    e1.setProperty("type", "1");
    Node e2 = d.addNode("e2");
    e2.setProperty("type", "2");
    Node e3 = d.addNode("e3");
    e3.setProperty("type", "3");
    session.save();
    String xpath = "/jcr:root/testroot//b/c/d/*[@jcr:uuid='1' or @jcr:uuid='2'] ";
    String sql2 = "select d.[jcr:path] as [jcr:path], d.[jcr:score] as [jcr:score], d.* " + "from [nt:base] as a inner join [nt:base] as b on ischildnode(b, a) " + "inner join [nt:base] as c on ischildnode(c, b) " + "inner join [nt:base] as d on ischildnode(d, c) " + "where name(a) = 'b' " + "and isdescendantnode(a, '/testroot') " + "and name(b) = 'c' " + "and name(c) = 'd' " + "and (d.[jcr:uuid] = '1' or d.[jcr:uuid] = '2')";
    sql2 = "select d.[jcr:path] as [jcr:path], d.[jcr:score] as [jcr:score], d.* " + "from [nt:base] as d " + "where (d.[jcr:uuid] = '1' or d.[jcr:uuid] = '2')";
    sql2 = "select d.[jcr:path] as [jcr:path], d.[jcr:score] as [jcr:score], d.* " + "from [nt:base] as d " + "inner join [nt:base] as c on ischildnode(d, c) " + "inner join [nt:base] as b on ischildnode(c, b) " + "inner join [nt:base] as a on ischildnode(b, a) " + "where name(a) = 'b' " + "and isdescendantnode(a, '/testroot') " + "and name(b) = 'c' " + "and name(c) = 'd' " + "and (d.[jcr:uuid] = '1' or d.[jcr:uuid] = '2')";
    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();
    assertEquals("", plan);
    // [nt:base] as [a] /* traverse "/testroot//*" 
    // where (name([a]) = cast('b' as string)) 
    // and (isdescendantnode([a], [/testroot])) */ 
    // inner join [nt:base] as [b] /* traverse 
    // "/path/from/the/join/selector/*" where name([b]) = cast('c' as string) */ 
    // on ischildnode([b], [a]) inner join [nt:base] as [c] 
    // /* traverse "/path/from/the/join/selector/*"
    // where name([c]) = cast('d' as string) */ on ischildnode([c], [b]) 
    // inner join [nt:base] as [d] /* traverse "/path/from/the/join/selector/*" 
    // where ([d].[type] is not null) and ([d].[type] in(cast('1' as string), cast('2' as string))) */ 
    // on ischildnode([d], [c])
    //        assertEquals("[nt:base] as [nt:base] /* traverse \"*\" " + 
    //                "where [nt:base].[node2/node3/jcr:primaryType] is not null */", 
    //                plan);
    // verify the result
    q = qm.createQuery(xpath, "xpath");
    result = q.execute();
    it = result.getRows();
    assertTrue(it.hasNext());
    String path = it.nextRow().getValue("path").getString();
    assertEquals("/testroot/b/c/d/e1", path);
    path = it.nextRow().getValue("path").getString();
    assertEquals("/testroot/b/c/d/e2", path);
    assertFalse(it.hasNext());
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

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