Search in sources :

Example 1 with Ordering

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);
}
Also used : Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) PropertyExistence(javax.jcr.query.qom.PropertyExistence) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector)

Example 2 with Ordering

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);
}
Also used : Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue)

Example 3 with Ordering

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();
}
Also used : Constraint(javax.jcr.query.qom.Constraint) Ordering(javax.jcr.query.qom.Ordering)

Example 4 with Ordering

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();
}
Also used : Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) Constraint(javax.jcr.query.qom.Constraint)

Example 5 with Ordering

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]);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) PropertyValue(javax.jcr.query.qom.PropertyValue) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Selector(javax.jcr.query.qom.Selector) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Aggregations

Ordering (javax.jcr.query.qom.Ordering)18 PropertyValue (javax.jcr.query.qom.PropertyValue)9 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)6 Selector (javax.jcr.query.qom.Selector)6 Column (javax.jcr.query.qom.Column)5 Constraint (javax.jcr.query.qom.Constraint)4 PropertyExistence (javax.jcr.query.qom.PropertyExistence)4 Source (javax.jcr.query.qom.Source)3 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BindVariableValue (javax.jcr.query.qom.BindVariableValue)2 DynamicOperand (javax.jcr.query.qom.DynamicOperand)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 Operand (javax.jcr.query.qom.Operand)1 DynamicOperandFieldComparatorSource (org.apache.jackrabbit.core.query.lucene.sort.DynamicOperandFieldComparatorSource)1 SortField (org.apache.lucene.search.SortField)1