use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryFulltextTest method fulltextOrWithinText.
@Test
public void fulltextOrWithinText() throws Exception {
Session session = getAdminSession();
QueryManager qm = session.getWorkspace().getQueryManager();
Node testRootNode = session.getRootNode().addNode("testroot");
Node n1 = testRootNode.addNode("node1");
n1.setProperty("text", "hello");
Node n2 = testRootNode.addNode("node2");
n2.setProperty("text", "hallo");
Node n3 = testRootNode.addNode("node3");
n3.setProperty("text", "hello hallo");
session.save();
String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where contains([text], 'hello OR hallo') order by [jcr:path]";
Query q;
q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
assertEquals("[nt:base] as [nt:base] /* traverse \"*\" " + "where contains([nt:base].[text], 'hello OR hallo') */", getResult(q.execute(), "plan"));
// verify the result
// uppercase "OR" mean logical "or"
q = qm.createQuery(sql2, Query.JCR_SQL2);
assertEquals("/testroot/node1, /testroot/node2, /testroot/node3", getResult(q.execute(), "path"));
// lowercase "or" mean search for the term "or"
sql2 = "select [jcr:path] as [path] from [nt:base] " + "where contains([text], 'hello or hallo') order by [jcr:path]";
q = qm.createQuery(sql2, Query.JCR_SQL2);
assertEquals("", getResult(q.execute(), "path"));
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryTest method noLiterals.
@Test
public void noLiterals() throws RepositoryException {
Session session = getAdminSession();
ValueFactory vf = session.getValueFactory();
QueryManager qm = session.getWorkspace().getQueryManager();
// insecure
try {
Query q = qm.createQuery("select text from [nt:base] where password = 'x'", Query.JCR_SQL2 + "-noLiterals");
q.execute();
fail();
} catch (InvalidQueryException e) {
assertTrue(e.toString(), e.toString().indexOf("literals of this type not allowed") > 0);
}
// secure
Query q = qm.createQuery("select text from [nt:base] where password = $p", Query.JCR_SQL2 + "-noLiterals");
q.bindValue("p", vf.createValue("x"));
q.execute();
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryTest method fnNameEncoding.
@SuppressWarnings("deprecation")
@Test
public void fnNameEncoding() throws Exception {
Session session = getAdminSession();
session.getRootNode().addNode("123456_test_name");
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q;
q = qm.createQuery("//*[jcr:like(fn:name(), '%123456%')]", Query.XPATH);
assertEquals("/123456_test_name", getPaths(q));
q = qm.createQuery("//*[fn:name() = '123456_test_name']", Query.XPATH);
assertEquals("", getPaths(q));
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class QueryTest method getValuesOnMvp.
/**
* OAK-1093
*/
@Test
public void getValuesOnMvp() throws RepositoryException {
Session session = getAdminSession();
Node hello = session.getRootNode().addNode("hello");
hello.setProperty("id", "1");
hello.setProperty("properties", new String[] { "p1", "p2" });
session.save();
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("select properties from [nt:base] where id = 1", Query.JCR_SQL2);
QueryResult r = q.execute();
RowIterator it = r.getRows();
assertTrue(it.hasNext());
Row row = it.nextRow();
assertEquals("p1 p2", row.getValues()[0].getString());
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class RemappingTest method testQuery1.
public void testQuery1() throws Exception {
String statement = createStatement("my:property", "stringValue");
QueryManager qm = session.getWorkspace().getQueryManager();
QueryResult qr = qm.createQuery(statement, "xpath").execute();
// xpath:
// /jcr:root/testroot/my:node//element(*)[@my:property='stringValue']
// select [jcr:path], [jcr:score], * from [nt:base] as a
// where [my:property] = 'stringValue'
// and isdescendantnode(a, '/testroot/my:node')
NodeIterator ni = qr.getNodes();
assertTrue(ni.hasNext());
assertEquals(resultPath, ni.nextNode().getPath());
}
Aggregations