use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class NodeLocalNameTest method testDoubleLiteral.
public void testDoubleLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(Math.PI);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
checkQOM(qom, new Node[] {});
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class OrderingTest method testMultipleSelectors.
public void testMultipleSelectors() throws RepositoryException {
// ascending
Ordering[] orderings = new Ordering[] { qf.ascending(qf.propertyValue(LEFT, propertyName2)) };
QueryObjectModel qom = createQuery(orderings);
checkResultOrder(qom, SELECTOR_NAMES, new Node[][] { { n2, n2 }, { n1, n2 } });
// descending
orderings[0] = qf.descending(qf.propertyValue(LEFT, propertyName2));
qom = createQuery(orderings);
checkResultOrder(qom, SELECTOR_NAMES, new Node[][] { { n1, n2 }, { n2, n2 } });
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class PropertyValueTest method testPropertyExistence.
public void testPropertyExistence() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
n1.setProperty(propertyName1, TEXT);
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
n2.setProperty(propertyName2, TEXT);
superuser.save();
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.propertyValue("s", propertyName1), QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, qf.literal(vf.createValue(TEXT)))), null, null);
checkQOM(qom, new Node[] { n1 });
qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.and(qf.childNode("s", testRoot), qf.comparison(qf.propertyValue("s", propertyName2), QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO, qf.literal(vf.createValue(TEXT)))), null, null);
checkQOM(qom, new Node[] { n2 });
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class ColumnTest method testExpandColumnsForNodeType.
/**
* From the spec:
* <p>
* If propertyName is not specified, a column is included for each
* single-valued non-residual property of the node type specified by the
* nodeType attribute of the selector selectorName.
* <p>
* [..] If propertyName is not specified,
* columnName must not be specified, and the included columns will be
* named "selectorName.propertyName".
*/
public void testExpandColumnsForNodeType() throws RepositoryException {
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_1), null, null, new Column[] { qf.column(SELECTOR_1, null, null) });
forQOMandSQL2(qom, new Callable() {
public Object call(Query query) throws RepositoryException {
QueryResult result = query.execute();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeType nt = ntMgr.getNodeType(testNodeType);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
Set<String> names = new HashSet<String>();
for (int i = 0; i < propDefs.length; i++) {
PropertyDefinition propDef = propDefs[i];
if (!propDef.isMultiple() && !propDef.getName().equals("*")) {
String columnName = SELECTOR_1 + "." + propDef.getName();
names.add(columnName);
}
}
for (String columnName : result.getColumnNames()) {
names.remove(columnName);
}
assertTrue("Missing required column(s): " + names, names.isEmpty());
return null;
}
});
}
use of javax.jcr.query.qom.QueryObjectModel 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;
}
});
}
Aggregations