use of javax.jcr.query.qom.Ordering in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraintAndOrdering.
public void testCreateQueryFromSourceWithConstraintAndOrdering() 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);
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.Ordering in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testOrderingDescending.
/**
* Test case for {@link QueryObjectModelFactory#descending(DynamicOperand)}
*/
public void testOrderingDescending() throws RepositoryException {
PropertyValue op = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering desc = qf.descending(op);
assertEquals("Ordering.getOrder() must return QueryObjectModelConstants.ORDER_DESCENDING", QueryObjectModelConstants.JCR_ORDER_DESCENDING, desc.getOrder());
assertTrue("Not a PropertyValue operand", desc.getOperand() instanceof PropertyValue);
}
use of javax.jcr.query.qom.Ordering in project jackrabbit by apache.
the class QOMFormatter method format.
private String format() throws RepositoryException {
append("SELECT ");
append(qom.getColumns());
append(" FROM ");
append(qom.getSource());
Constraint c = qom.getConstraint();
if (c != null) {
append(" WHERE ");
append(c);
}
Ordering[] orderings = qom.getOrderings();
if (orderings.length > 0) {
append(" ORDER BY ");
append(orderings);
}
return sb.toString();
}
use of javax.jcr.query.qom.Ordering in project jackrabbit-oak by apache.
the class QueryObjectModelImpl method getStatement.
@Override
public String getStatement() {
StringBuilder buff = new StringBuilder();
buff.append("select ");
int i;
if (columns != null && columns.length > 0) {
i = 0;
for (Column c : columns) {
if (i++ > 0) {
buff.append(", ");
}
buff.append(c);
}
} else {
buff.append("*");
}
buff.append(" from ");
buff.append(source);
if (constraint != null) {
buff.append(" where ");
buff.append(constraint);
}
if (orderings != null && orderings.length > 0) {
buff.append(" order by ");
i = 0;
for (Ordering o : orderings) {
if (i++ > 0) {
buff.append(", ");
}
buff.append(o);
}
}
return buff.toString();
}
use of javax.jcr.query.qom.Ordering 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]);
}
Aggregations