use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class SearchScalabilityBenchmark method execute.
@Override
public void execute(Repository repository, Credentials credentials, ExecutionContext context) throws Exception {
Session session = repository.login(credentials);
QueryManager qm;
try {
qm = session.getWorkspace().getQueryManager();
search(qm, context);
} catch (RepositoryException e) {
e.printStackTrace();
}
}
use of javax.jcr.query.QueryManager 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.QueryManager in project jackrabbit-oak by apache.
the class OperationLoggerTest method testQueryLogger.
public void testQueryLogger() throws Exception {
Node node1 = testRootNode.addNode(nodeName1);
//Log batch size is 100
for (int i = 0; i < 200; i++) {
node1.addNode("foo" + i, "oak:Unstructured").setProperty("foo", "bar");
}
superuser.save();
QueryManager qm = superuser.getWorkspace().getQueryManager();
start();
String stmt = "select * from [nt:base] where foo = 'bar'";
Query q = qm.createQuery(stmt, Query.JCR_SQL2);
QueryResult r = q.execute();
Iterators.size(r.getRows());
stop();
boolean queryStmtLog = false;
boolean queryIterationLog = false;
for (ILoggingEvent e : logs.list) {
if (OPS_QUERY.equals(e.getLoggerName())) {
if (e.getMessage().contains("Executed query")) {
assertEquals(stmt, e.getArgumentArray()[0]);
assertTrue(e.getArgumentArray()[1] instanceof Number);
queryStmtLog = true;
}
if (e.getMessage().contains("Iterated over")) {
queryIterationLog = true;
}
}
}
assertTrue("Did not find query log", queryStmtLog);
assertTrue("Did not find query iteration log", queryIterationLog);
}
use of javax.jcr.query.QueryManager 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());
}
use of javax.jcr.query.QueryManager 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);
}
Aggregations