use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method propertyIndexWithDeclaringNodeTypeAndRelativQuery.
@Test
public void propertyIndexWithDeclaringNodeTypeAndRelativQuery() throws RepositoryException {
Session session = getAdminSession();
RowIterator rit;
QueryResult r;
String query;
query = "//element(*, rep:Authorizable)[@rep:principalName = 'admin']";
r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
rit = r.getRows();
assertEquals("[rep:Authorizable] as [a] /* property principalName = admin " + "where [a].[rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
query = "//element(*, rep:Authorizable)[admin/@rep:principalName = 'admin']";
r = session.getWorkspace().getQueryManager().createQuery("explain " + query, "xpath").execute();
rit = r.getRows();
assertEquals("[rep:Authorizable] as [a] /* nodeType " + "Filter(query=explain select [jcr:path], [jcr:score], * " + "from [rep:Authorizable] as a " + "where [admin/rep:principalName] = 'admin' " + "/* xpath: //element(*, rep:Authorizable)[" + "admin/@rep:principalName = 'admin'] */, path=*, " + "property=[admin/rep:principalName=[admin]]) " + "where [a].[admin/rep:principalName] = 'admin' */", rit.nextRow().getValue("plan").getString());
}
use of javax.jcr.Session 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);
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryPlanTest method nodeType.
@Test
public void nodeType() throws Exception {
Session session = getAdminSession();
QueryManager qm = session.getWorkspace().getQueryManager();
Node nodetype = session.getRootNode().getNode("oak:index").getNode("nodetype");
nodetype.setProperty("entryCount", 10000000);
Node testRootNode = session.getRootNode().addNode("testroot");
Node n1 = testRootNode.addNode("node1");
Node n2 = n1.addNode("node2");
n2.addNode("node3");
session.save();
String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where [node2/node3/jcr:primaryType] is not null " + "and isdescendantnode('/testroot')";
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();
// should not use the index on "jcr:primaryType"
assertEquals("[nt:base] as [nt:base] /* traverse \"/testroot//*\" " + "where ([nt:base].[node2/node3/jcr:primaryType] is not null) " + "and (isdescendantnode([nt:base], [/testroot])) " + "*/", plan);
// verify the result
q = qm.createQuery(sql2, Query.JCR_SQL2);
result = q.execute();
it = result.getRows();
assertTrue(it.hasNext());
String path = it.nextRow().getValue("path").getString();
assertEquals("/testroot/node1", path);
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method encodedPath.
@SuppressWarnings("deprecation")
@Test
public void encodedPath() throws RepositoryException {
Session session = getAdminSession();
session.getRootNode().addNode("hello").addNode("world");
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q;
q = qm.createQuery("/jcr:root/hel_x006c_o/*", Query.XPATH);
assertEquals("/hello/world", getPaths(q));
q = qm.createQuery("//hel_x006c_o", Query.XPATH);
assertEquals("/hello", getPaths(q));
q = qm.createQuery("//element(hel_x006c_o, nt:base)", Query.XPATH);
assertEquals("/hello", getPaths(q));
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class UserManagerTest method testNewUserCanLogin.
@Test
public void testNewUserCanLogin() throws RepositoryException, NotExecutableException {
String uid = createUserId();
User u = null;
Session s = null;
try {
u = userMgr.createUser(uid, "pw");
superuser.save();
Credentials creds = new SimpleCredentials(uid, "pw".toCharArray());
s = superuser.getRepository().login(creds);
} finally {
if (u != null) {
u.remove();
superuser.save();
}
if (s != null) {
s.logout();
}
}
}
Aggregations