use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testNotEqual.
public void testNotEqual() throws Exception {
Node n = testRootNode.addNode("node1");
n.setProperty("value", new String[] { "foo" });
n = testRootNode.addNode("node2");
n.setProperty("value", new String[] { "bar" });
n = testRootNode.addNode("node3");
n.setProperty("value", new String[] { "foobar" });
testRootNode.save();
String jcrql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value <> 'bar'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(jcrql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 2);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testIsNull.
public void testIsNull() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("mytext", "the quick brown fox jumps over the lazy dog.");
Node bar = testRootNode.addNode("bar");
bar.setProperty("text", "the quick brown fox jumps over the lazy dog.");
testRootNode.save();
String sql = "SELECT * FROM nt:unstructured WHERE mytext is null and jcr:path LIKE '" + testRoot + "/%'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and fn:not(@mytext)]";
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
result = q.execute();
checkResult(result, 1);
xpath = "/jcr:root" + testRoot + "/*[@jcr:primaryType='nt:unstructured' and fn:not(@mytext)]";
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
result = q.execute();
checkResult(result, 1);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testLikePatternBetween.
public void testLikePatternBetween() throws Exception {
Node n = testRootNode.addNode("node1");
n.setProperty("value", new String[] { "ping" });
n = testRootNode.addNode("node2");
n.setProperty("value", new String[] { "pong" });
n = testRootNode.addNode("node3");
n.setProperty("value", new String[] { "puung" });
testRootNode.save();
String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'ping'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'p_ng'";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 2);
sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'p%ng'";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 3);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testLikePattern.
public void testLikePattern() throws Exception {
Node n = testRootNode.addNode("node1");
n.setProperty("value", new String[] { "king" });
n = testRootNode.addNode("node2");
n.setProperty("value", new String[] { "ping" });
n = testRootNode.addNode("node3");
n.setProperty("value", new String[] { "ching" });
testRootNode.save();
String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'ping'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE '_ing'";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 2);
sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE '%ing'";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 3);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testIsNotNull.
public void testIsNotNull() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("mytext", "the quick brown fox jumps over the lazy dog.");
Node bar = testRootNode.addNode("bar");
bar.setProperty("text", "the quick brown fox jumps over the lazy dog.");
// documents which field name is not exactly "mytext" should not match (JCR-1051)
bar.setProperty("mytextwhichstartswithmytext", "the quick brown fox jumps over the lazy dog.");
testRootNode.save();
String sql = "SELECT * FROM nt:unstructured WHERE mytext is not null";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
String xpath = "//*[@jcr:primaryType='nt:unstructured' and @mytext]";
q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
result = q.execute();
checkResult(result, 1);
}
Aggregations