use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SimpleQueryTest method testDoubleField.
public void testDoubleField() throws Exception {
Node n = testRootNode.addNode("node1");
n.setProperty("value", new Value[] { superuser.getValueFactory().createValue(1.9928375d) });
n = testRootNode.addNode("node2");
n.setProperty("value", new Value[] { superuser.getValueFactory().createValue(0.0d) });
n = testRootNode.addNode("node3");
n.setProperty("value", new Value[] { superuser.getValueFactory().createValue(-1.42982475d) });
testRootNode.save();
String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value > 0.1e-0";
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 > -0.1";
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 > -1.5";
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 testDateField1.
public void testDateField1() throws Exception {
Node n = testRootNode.addNode("marcel");
Calendar marcel = Calendar.getInstance();
marcel.set(1976, 4, 20, 15, 40);
n.setProperty("birth", new Value[] { superuser.getValueFactory().createValue(marcel) });
n = testRootNode.addNode("vanessa");
Calendar vanessa = Calendar.getInstance();
vanessa.set(1975, 4, 10, 13, 30);
n.setProperty("birth", new Value[] { superuser.getValueFactory().createValue(vanessa) });
testRootNode.save();
String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND birth > TIMESTAMP '1976-01-01T00:00:00.000+01:00'";
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 birth > TIMESTAMP '1975-01-01T00:00:00.000+01:00'";
q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
result = q.execute();
checkResult(result, 2);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryResultTest method testSkipOrderByProperty.
public void testSkipOrderByProperty() throws RepositoryException {
QueryManager qm = superuser.getWorkspace().getQueryManager();
for (int i = 0; i < 10; i++) {
String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by @" + propertyName1;
QueryResult result = qm.createQuery(stmt, Query.XPATH).execute();
for (int j = 0; j < INITIAL_NODE_NUM - i; j++) {
// skip to each node in the result
NodeIterator it = result.getNodes();
it.skip(j);
long propValue = it.nextNode().getProperty(propertyName1).getLong();
// expected = number of skipped nodes + number of deleted nodes
long expected = j + i;
assertEquals("Wrong node after skip()", expected, propValue);
}
try {
NodeIterator it = result.getNodes();
it.skip(it.getSize() + 1);
fail("must throw NoSuchElementException");
} catch (NoSuchElementException 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 testGetSize.
public void testGetSize() 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();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// 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 testGetSizeOrderByScore.
public void testGetSizeOrderByScore() 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();
assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize());
// remove node for the next iteration
testRootNode.getNode("node" + i).remove();
testRootNode.save();
}
}
Aggregations