use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class XPathJcrPathTest method testJcrPath.
/**
* Verify that the jcr:path is present in the query result.
*/
public void testJcrPath() throws RepositoryException, NotExecutableException {
String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName();
String queryStatement = "//element(*, " + nodeTypeName + ")";
// execute the search query
Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement, qsXPATH);
QueryResult result = query.execute();
assertTrue("jcr:path must be present in query result row", Arrays.asList(result.getColumnNames()).contains(jcrPath));
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class XPathPosIndexTest method docOrderTest.
//-----------------------------< internal >---------------------------------
/**
* Executes a statement, checks if the Result contains exactly one node with
* <code>path</code>.
*
* @param stmt to be executed
* @param path the path of the node in the query result.
*/
private void docOrderTest(Statement stmt, String path) throws RepositoryException, NotExecutableException {
if (!isSupported(Repository.QUERY_XPATH_POS_INDEX)) {
throw new NotExecutableException("Repository does not support document order on result set.");
}
int count = 0;
// check precondition: at least 3 nodes
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); it.nextNode()) {
count++;
}
if (count < 3) {
throw new NotExecutableException("Workspace does not contain enough content under: " + testRoot + ". At least 3 nodes are required for this test.");
}
QueryResult result = execute(stmt);
checkResult(result, 1);
assertEquals("Wrong result node.", path, result.getNodes().nextNode().getPath());
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class XPathQueryLevel2Test method testPathColumn.
/**
* Test if the jcr:path pseudo property is contained in result.
* <p>
* For configuration description see {@link #setUpFullTextTest()}.
*/
public void testPathColumn() throws Exception {
setUpFullTextTest();
QueryResult result = execute(getFullTextStatement());
RowIterator rows = result.getRows();
if (getSize(rows) < 1) {
fail("Query result did not return any nodes");
}
// re-aquire rows
rows = result.getRows();
// test mere existence
rows.nextRow().getValue(jcrPath);
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class LengthTest method executeQueries.
private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException {
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.length(qf.propertyValue("s", propertyName)), operator, qf.literal(length))), null, null);
QueryResult[] results = new QueryResult[2];
results[0] = qom.execute();
results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute();
return results;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class AndConstraintTest method testAnd.
public void testAnd() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
n1.setProperty(propertyName1, "foo");
n1.setProperty(propertyName2, "bar");
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
n2.setProperty(propertyName2, "bar");
superuser.save();
QueryResult result = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.descendantNode("s", testRootNode.getPath()), qf.and(qf.propertyExistence("s", propertyName1), qf.propertyExistence("s", propertyName2))), null, null).execute();
checkResult(result, new Node[] { n1 });
String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + testRootNode.getPath() + "]) " + "AND s.[" + propertyName1 + "] IS NOT NULL " + "AND s.[" + propertyName2 + "] IS NOT NULL";
result = qm.createQuery(stmt, Query.JCR_SQL2).execute();
checkResult(result, new Node[] { n1 });
}
Aggregations