use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method anyChildNodeProperty.
@Test
@Ignore("OAK-1215")
public void anyChildNodeProperty() throws Exception {
Session session = getAdminSession();
Node content = session.getRootNode().addNode("test");
content.addNode("one").addNode("child").setProperty("prop", "hello");
content.addNode("two").addNode("child").setProperty("prop", "hi");
session.save();
String query = "//*[*/@prop = 'hello']";
QueryResult r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
NodeIterator it = r.getNodes();
assertTrue(it.hasNext());
String path = it.nextNode().getPath();
assertEquals("/test/one", path);
assertFalse(it.hasNext());
query = "//*[*/*/@prop = 'hello']";
r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
it = r.getNodes();
assertTrue(it.hasNext());
path = it.nextNode().getPath();
assertEquals("/test", path);
assertFalse(it.hasNext());
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method testOak1354.
@Test
public void testOak1354() throws Exception {
Session session = createAdminSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
if (!manager.hasNodeType("mymixinOak1354")) {
StringBuilder defs = new StringBuilder();
defs.append("[mymixinOak1354]\n");
defs.append(" mixin");
Reader cndReader = new InputStreamReader(new ByteArrayInputStream(defs.toString().getBytes()));
CndImporter.registerNodeTypes(cndReader, session);
}
Node p = session.getRootNode().addNode("one");
p.addMixin("mymixinOak1354");
session.save();
Query q = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM [mymixinOak1354]", Query.JCR_SQL2);
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
assertTrue(ni.hasNext());
Node n = ni.nextNode();
assertEquals("/one", n.getPath());
assertFalse(ni.hasNext());
session.logout();
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method testOak1128.
@Test
public void testOak1128() throws RepositoryException {
Session session = createAdminSession();
Node p = session.getRootNode().addNode("etc");
p.addNode("p1");
Node r = p.addNode("p2").addNode("r", "nt:unstructured");
r.setProperty("nt:resourceType", "test");
session.save();
Query q = session.getWorkspace().getQueryManager().createQuery("/jcr:root/etc//*[" + "(@jcr:primaryType = 'nt:file' or @jcr:primaryType = 'nt:folder') " + "or @nt:resourceType = 'test']", "xpath");
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
Node n = ni.nextNode();
assertEquals("/etc/p2/r", n.getPath());
session.logout();
}
use of javax.jcr.Session in project jackrabbit-oak by apache.
the class QueryTest method date.
@Test
public void date() throws Exception {
Session session = getAdminSession();
Node t1 = session.getRootNode().addNode("t1");
t1.setProperty("x", "22.06.07");
Node t2 = session.getRootNode().addNode("t2");
t2.setProperty("x", "2007-06-22T01:02:03.000Z", PropertyType.DATE);
session.save();
String query = "//*[x='a' or x='b']";
QueryResult r = session.getWorkspace().getQueryManager().createQuery(query, "xpath").execute();
NodeIterator it = r.getNodes();
assertFalse(it.hasNext());
}
use of javax.jcr.Session 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));
}
Aggregations