use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class ColumnTest method testMultiColumn.
public void testMultiColumn() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
n.setProperty(propertyName1, TEST_VALUE);
superuser.save();
final String columnName1 = SELECTOR_1 + "." + propertyName1;
final String columnName2 = SELECTOR_2 + "." + propertyName1;
QueryObjectModel qom = qf.createQuery(qf.join(qf.selector(testNodeType, SELECTOR_1), qf.selector(testNodeType, SELECTOR_2), QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, qf.equiJoinCondition(SELECTOR_1, propertyName1, SELECTOR_2, propertyName1)), qf.descendantNode(SELECTOR_1, testRoot), null, new Column[] { qf.column(SELECTOR_1, propertyName1, columnName1), qf.column(SELECTOR_2, propertyName1, columnName2) });
forQOMandSQL2(qom, new Callable() {
public Object call(Query query) throws RepositoryException {
RowIterator rows = query.execute().getRows();
assertTrue("empty result", rows.hasNext());
Row r = rows.nextRow();
assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
return null;
}
});
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class AbstractQOMTest method checkResult.
protected void checkResult(QueryResult result, String[] selectorNames, Node[][] nodes) throws RepositoryException {
// collect rows
Set<String> expectedPaths = new HashSet<String>();
log.println("expected:");
for (int i = 0; i < nodes.length; i++) {
StringBuffer aggregatedPaths = new StringBuffer();
for (int j = 0; j < nodes[i].length; j++) {
aggregatedPaths.append(getPath(nodes[i][j]));
aggregatedPaths.append("|");
}
expectedPaths.add(aggregatedPaths.toString());
log.println(aggregatedPaths.toString());
}
Set<String> resultPaths = new HashSet<String>();
log.println("result:");
for (RowIterator it = result.getRows(); it.hasNext(); ) {
Row r = it.nextRow();
StringBuffer aggregatedPaths = new StringBuffer();
for (int i = 0; i < selectorNames.length; i++) {
aggregatedPaths.append(getPath(r.getNode(selectorNames[i])));
aggregatedPaths.append("|");
}
resultPaths.add(aggregatedPaths.toString());
log.println(aggregatedPaths.toString());
}
// check if all expected are in result
for (Iterator<String> it = expectedPaths.iterator(); it.hasNext(); ) {
String path = it.next();
assertTrue(path + " is not part of the result set", resultPaths.contains(path));
}
// check result does not contain more than expected
for (Iterator<String> it = resultPaths.iterator(); it.hasNext(); ) {
String path = it.next();
assertTrue(path + " is not expected to be part of the result set", expectedPaths.contains(path));
}
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class AbstractQOMTest method checkResultOrder.
protected void checkResultOrder(QueryResult result, String[] selectorNames, Node[][] nodes) throws RepositoryException {
// collect rows
List<String> expectedPaths = new ArrayList<String>();
log.println("expected:");
for (int i = 0; i < nodes.length; i++) {
StringBuffer aggregatedPaths = new StringBuffer();
for (int j = 0; j < nodes[i].length; j++) {
aggregatedPaths.append(getPath(nodes[i][j]));
aggregatedPaths.append("|");
}
expectedPaths.add(aggregatedPaths.toString());
log.println(aggregatedPaths.toString());
}
List<String> resultPaths = new ArrayList<String>();
log.println("result:");
for (RowIterator it = result.getRows(); it.hasNext(); ) {
Row r = it.nextRow();
StringBuffer aggregatedPaths = new StringBuffer();
for (int i = 0; i < selectorNames.length; i++) {
aggregatedPaths.append(getPath(r.getNode(selectorNames[i])));
aggregatedPaths.append("|");
}
resultPaths.add(aggregatedPaths.toString());
log.println(aggregatedPaths.toString());
}
assertEquals("wrong result order", expectedPaths, resultPaths);
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class FullTextSearchScoreTest method testConstraint.
public void testConstraint() throws RepositoryException {
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.and(qf.fullTextSearch("s", null, qf.literal(vf.createValue("fox"))), qf.comparison(qf.fullTextSearchScore("s"), QueryObjectModelFactory.JCR_OPERATOR_GREATER_THAN, qf.literal(vf.createValue(Double.MIN_VALUE)))), qf.descendantNode("s", testRootNode.getPath())), new Ordering[] { qf.descending(qf.fullTextSearchScore("s")) }, null);
forQOMandSQL2(qom, new Callable() {
public Object call(Query query) throws RepositoryException {
RowIterator rows = query.execute().getRows();
while (rows.hasNext()) {
double score = rows.nextRow().getScore("s");
if (!Double.isNaN(score)) {
assertTrue("wrong full text search score", Double.MIN_VALUE < score);
}
}
return null;
}
});
}
use of javax.jcr.query.RowIterator in project jackrabbit by apache.
the class SQLQueryLevel2Test method testPathColumn.
/**
* Test if the optional jcr:path pseudo property is contained in the query
* 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);
}
Aggregations