hello2.setProperty("text", "hello world");
session.save();
ValueFactory vf = session.getValueFactory();
QueryManager qm = session.getWorkspace().getQueryManager();
// SQL-2
Query q = qm.createQuery("select text from [nt:base] where id = $id", Query.JCR_SQL2);
q.bindValue("id", vf.createValue("1"));
QueryResult r = q.execute();
RowIterator it = r.getRows();
assertTrue(it.hasNext());
Row row = it.nextRow();
assertEquals("hello_world", row.getValue("text").getString());
String[] columns = r.getColumnNames();
assertEquals(1, columns.length);
assertEquals("text", columns[0]);
assertFalse(it.hasNext());
r = q.execute();
NodeIterator nodeIt = r.getNodes();
assertTrue(nodeIt.hasNext());
Node n = nodeIt.nextNode();
assertEquals("hello_world", n.getProperty("text").getString());
assertFalse(it.hasNext());
// SQL
q = qm.createQuery("select text from [nt:base] where text like 'hello\\_world' escape '\\'", Query.SQL);
r = q.execute();
columns = r.getColumnNames();
assertEquals(3, columns.length);
assertEquals("text", columns[0]);
assertEquals("jcr:path", columns[1]);
assertEquals("jcr:score", columns[2]);
nodeIt = r.getNodes();
assertTrue(nodeIt.hasNext());
n = nodeIt.nextNode();
assertEquals("hello_world", n.getProperty("text").getString());
assertFalse(nodeIt.hasNext());
// XPath
q = qm.createQuery("//*[@id=1]", Query.XPATH);
r = q.execute();
assertEquals(
newHashSet("jcr:path", "jcr:score", "jcr:primaryType"),
newHashSet(r.getColumnNames()));
}