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());
}
}
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;
}
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();
}
};
}
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();
}
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());
}
Aggregations