use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryPlanTest method propertyEqualsVersusPropertyNotNull.
@Test
public // OAK-1903
void propertyEqualsVersusPropertyNotNull() throws Exception {
Session session = getAdminSession();
QueryManager qm = session.getWorkspace().getQueryManager();
Node testRootNode = session.getRootNode().addNode("testroot");
createPropertyIndex(session, "notNull");
createPropertyIndex(session, "equals");
for (int i = 0; i < 100; i++) {
Node n = testRootNode.addNode("n" + i, "oak:Unstructured");
if (i % 2 == 0) {
n.setProperty("notNull", i);
}
n.setProperty("equals", 1);
}
session.save();
String xpath = "/jcr:root//*[@notNull and @equals=1]";
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();
// System.out.println("plan: " + plan);
// should not use the index on "jcr:uuid"
assertEquals("[nt:base] as [a] /* property notNull IS NOT NULL " + "where ([a].[notNull] is not null) " + "and ([a].[equals] = 1) " + "and (isdescendantnode([a], [/])) */", plan);
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryTest method getValuesOnMvp.
/**
* OAK-1093
*/
@Test
public void getValuesOnMvp() throws RepositoryException {
Session session = getAdminSession();
Node hello = session.getRootNode().addNode("hello");
hello.setProperty("id", "1");
hello.setProperty("properties", new String[] { "p1", "p2" });
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("select properties from [nt:base] where id = 1", Query.JCR_SQL2);
QueryResult r = q.execute();
RowIterator it = r.getRows();
assertTrue(it.hasNext());
Row row = it.nextRow();
assertEquals("p1 p2", row.getValues()[0].getString());
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryTest method firstSelector.
@Test
public void firstSelector() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
Node a = root.addNode("a");
a.setProperty("test", true);
Node b = a.addNode("b");
b.setProperty("test", true);
session.save();
QueryResult r = session.getWorkspace().getQueryManager().createQuery("//a[@test]/b[@test]", "xpath").execute();
String firstSelector = r.getSelectorNames()[0];
RowIterator rows = r.getRows();
Row row = rows.nextRow();
String path = row.getPath(firstSelector);
assertEquals("/a/b", path);
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryTest method getPaths.
private static String getPaths(Query q) throws RepositoryException {
QueryResult r = q.execute();
RowIterator it = r.getRows();
StringBuilder buff = new StringBuilder();
if (it.hasNext()) {
Row row = it.nextRow();
if (buff.length() > 0) {
buff.append(", ");
}
buff.append(row.getPath());
}
return buff.toString();
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class QueryTest method nodeTypeConstraint.
@SuppressWarnings("deprecation")
@Test
public void nodeTypeConstraint() throws Exception {
Session session = getAdminSession();
Node root = session.getRootNode();
Node folder1 = root.addNode("folder1", "nt:folder");
Node folder2 = root.addNode("folder2", "nt:folder");
JcrUtils.putFile(folder1, "file", "text/plain", new ByteArrayInputStream("foo bar".getBytes("UTF-8")));
folder2.addNode("folder3", "nt:folder");
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("//element(*, nt:folder)", Query.XPATH);
Set<String> paths = new HashSet<String>();
for (RowIterator it = q.execute().getRows(); it.hasNext(); ) {
paths.add(it.nextRow().getPath());
}
assertEquals(new HashSet<String>(Arrays.asList("/folder1", "/folder2", "/folder2/folder3")), paths);
}
Aggregations