use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryResultTest method testGetPosition.
public void testGetPosition() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000]";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
NodeIterator it = result.getNodes();
assertEquals("Wrong position", 0, it.getPosition());
int count = 0;
while (it.hasNext()) {
long position = it.getPosition();
it.nextNode();
assertEquals("Wrong position", count++, position);
}
try {
it.next();
fail("must throw NoSuchElementException");
} catch (Exception e) {
// correct
}
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryResultTest method testIteratorNextOrderByScore.
public void testIteratorNextOrderByScore() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()";
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
int size = 0;
for (NodeIterator it = result.getNodes(); it.hasNext(); ) {
it.nextNode();
size++;
}
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, size);
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SQLTest method testSimpleQuery1.
public void testSimpleQuery1() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("bla", new String[] { "bla" });
testRootNode.save();
String sql = "SELECT * FROM nt:unstructured WHERE bla='bla' " + "AND jcr:path LIKE '" + testRoot + "/%'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SQLTest method _testFulltextComplex.
/**
* I'm not sure what this test is supposed to verify. It only works because
* the sql parser is not strict enough and the column values are never
* actually checked
*/
public void _testFulltextComplex() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
testRootNode.save();
String sql = "SELECT foo.mytext, bla.foo FROM nt:unstructured WHERE " + "contains(., 'fox') AND NOT contains(., 'bla') " + "AND jcr:path LIKE '" + testRoot + "/%'";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 1);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SelectClauseTest method testSelectSQL.
public void testSelectSQL() throws RepositoryException {
Node n = testRootNode.addNode("node1");
n.setProperty("myvalue", "foo");
n = testRootNode.addNode("node2");
n.setProperty("myvalue", "bar");
n = testRootNode.addNode("node3");
n.setProperty("yourvalue", "foo");
testRootNode.save();
String sql = "SELECT myvalue FROM " + ntBase + " WHERE " + "jcr:path LIKE '" + testRoot + "/%' AND myvalue IS NOT NULL";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
QueryResult result = q.execute();
checkResult(result, 2);
sql = "SELECT myvalue FROM " + ntBase + " WHERE jcr:path LIKE '" + testRoot + "/%'" + " AND yourvalue = 'foo' AND myvalue IS NOT NULL";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 0);
sql = "SELECT myvalue FROM " + ntBase + " WHERE myvalue IS NOT NULL";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 2);
}
Aggregations