use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class RowTest method getRow.
private Row getRow() throws RepositoryException {
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[] { qf.column(SELECTOR_NAME, propertyName1, propertyName1) });
RowIterator rows = qom.execute().getRows();
assertTrue("empty result", rows.hasNext());
Row r = rows.nextRow();
assertFalse("result must not contain more than one row", rows.hasNext());
return r;
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit-oak by apache.
the class QomTest method createQuery.
@Test
public void createQuery() throws RepositoryException {
Selector s = f.selector("nt:file", "x");
BindVariableValue b = f.bindVariable("var");
Constraint c = f.propertyExistence("x", "c");
PropertyValue p = f.propertyValue("x", "propertyName");
c = f.and(f.comparison(p, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, b), c);
Ordering o = f.ascending(p);
Column col = f.column("x", "propertyName", "columnName");
Ordering[] ords = new Ordering[] { o };
Column[] cols = new Column[] { col };
QueryObjectModel q = f.createQuery(s, c, ords, cols);
assertEquals(Query.JCR_JQOM, q.getLanguage());
String[] bv = q.getBindVariableNames();
assertEquals(1, bv.length);
assertEquals("var", bv[0]);
assertEquals(s, q.getSource());
assertEquals(c, q.getConstraint());
assertEquals(o, q.getOrderings()[0]);
assertEquals(col, q.getColumns()[0]);
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintOrderingAndColumn.
public void testCreateQueryFromSourceWithConstraintOrderingAndColumn() throws RepositoryException {
Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering ordering = qf.ascending(propValue);
Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, new Column[] { column });
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
assertEquals("Wrong size of orderings", 1, qom.getOrderings().length);
assertEquals("Wrong size of columns", 1, qom.getColumns().length);
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryWithConstraintAndOrdering.
public void testCreateQueryWithConstraintAndOrdering() throws RepositoryException {
Selector selector = qf.selector(testNodeType, SELECTOR_NAME1);
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering ordering = qf.ascending(propValue);
QueryObjectModel qom = qf.createQuery(selector, propExist, new Ordering[] { ordering }, null);
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
assertTrue("Not a property existence constraint", qom.getConstraint() instanceof PropertyExistence);
assertEquals("Wrong size of orderings", 1, qom.getOrderings().length);
assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
use of javax.jcr.query.qom.QueryObjectModel in project jackrabbit by apache.
the class GetQueryTest method testGetQuery.
public void testGetQuery() throws RepositoryException, NotExecutableException {
checkNtQuery();
Node n = testRootNode.addNode(nodeName1, testNodeType);
superuser.save();
List<Query> queries = new ArrayList<Query>();
QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot), null, null);
queries.add(qom);
queries.add(qm.createQuery(qom.getStatement(), Query.JCR_SQL2));
if (isSupportedLanguage(qsXPATH)) {
String xpath = testPath + "/element(*, " + testNodeType + ")";
queries.add(qm.createQuery(xpath, qsXPATH));
}
if (isSupportedLanguage(qsSQL)) {
String sql = "select * from " + testNodeType + " where jcr:path like '" + testRoot + "/%'";
queries.add(qm.createQuery(sql, qsSQL));
}
for (Iterator<Query> it = queries.iterator(); it.hasNext(); ) {
Query q = it.next();
String lang = q.getLanguage();
checkResult(q.execute(), new Node[] { n });
Node stored = q.storeAsNode(testRoot + "/storedQuery");
q = qm.getQuery(stored);
assertEquals("language of stored query does not match", lang, q.getLanguage());
checkResult(q.execute(), new Node[] { n });
stored.remove();
}
}
Aggregations