use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryTest method xpathEscapeTest.
@SuppressWarnings("deprecation")
@Test
public void xpathEscapeTest() throws RepositoryException {
Session writer = createAdminSession();
Session reader = createAdminSession();
UserManager uMgr = ((JackrabbitSession) writer).getUserManager();
String uid = "testUser";
try {
User user = uMgr.createUser("testUser", "pw");
writer.getNode(user.getPath()).addNode(".tokens", "rep:Unstructured");
writer.save();
QueryManager qm = reader.getWorkspace().getQueryManager();
Query q = qm.createQuery("/jcr:root//*[_x002e_tokens/@jcr:primaryType]", Query.XPATH);
NodeIterator res = q.execute().getNodes();
assertEquals(1, res.getSize());
} finally {
Authorizable a = uMgr.getAuthorizable(uid);
if (a != null) {
a.remove();
writer.save();
}
if (reader != null) {
reader.logout();
}
if (writer != null) {
writer.logout();
}
}
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class RemappingTest method testQuery3.
public void testQuery3() throws Exception {
String statement = createStatement("my:nameProperty", "my:nameValue");
QueryManager qm = session.getWorkspace().getQueryManager();
QueryResult qr = qm.createQuery(statement, "xpath").execute();
NodeIterator ni = qr.getNodes();
assertTrue(ni.hasNext());
assertEquals(resultPath, ni.nextNode().getPath());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class RemappingTest method testQuery2.
public void testQuery2() throws Exception {
String statement = createStatement("my:booleanProperty", "true");
QueryManager qm = session.getWorkspace().getQueryManager();
QueryResult qr = qm.createQuery(statement, "xpath").execute();
NodeIterator ni = qr.getNodes();
assertTrue(ni.hasNext());
assertEquals(resultPath, ni.nextNode().getPath());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryTest method or.
@SuppressWarnings("deprecation")
@Test
public void or() throws RepositoryException {
Session session = getAdminSession();
Node hello = session.getRootNode().addNode("hello");
hello.setProperty("x", 1);
Node world = hello.addNode("world");
world.setProperty("x", 2);
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q;
q = qm.createQuery("select a.[jcr:path] from [nt:base] as a " + "inner join [nt:base] as b " + "on ischildnode(a, b) " + "where a.x = 1 or a.x = 2 or b.x = 3 or b.x = 4", Query.JCR_SQL2);
assertEquals("/hello", getPaths(q));
q = qm.createQuery("//hello[@x=1]/*[@x=2]", Query.XPATH);
assertEquals("/hello/world", getPaths(q));
}
use of javax.jcr.query.QueryManager 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);
}
Aggregations