Search in sources :

Example 11 with Ordering

use of javax.jcr.query.qom.Ordering in project jackrabbit by apache.

the class AbstractOrderByTest method createQOM.

/**
     * @return a basic QOM to test order by queries.
     * @throws RepositoryException if an error occurs.
     */
protected QueryObjectModel createQOM(boolean ascending) throws RepositoryException {
    DynamicOperand op = createOrderingOperand();
    Ordering ordering;
    if (ascending) {
        ordering = qf.ascending(op);
    } else {
        ordering = qf.descending(op);
    }
    return qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), new Ordering[] { ordering }, null);
}
Also used : DynamicOperand(javax.jcr.query.qom.DynamicOperand) Ordering(javax.jcr.query.qom.Ordering)

Example 12 with Ordering

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

use of javax.jcr.query.qom.Ordering 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);
}
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) Selector(javax.jcr.query.qom.Selector)

Example 14 with Ordering

use of javax.jcr.query.qom.Ordering in project jackrabbit by apache.

the class QueryObjectModelFactoryTest method testCreateQueryWithConstraintOrderingAndColumn.

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

Example 15 with Ordering

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

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