Search in sources :

Example 6 with Selector

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

the class Parser method parseSource.

private Source parseSource() throws RepositoryException {
    Selector selector = parseSelector();
    selectors.add(selector);
    Source source = selector;
    while (true) {
        JoinType type;
        if (readIf("RIGHT")) {
            read("OUTER");
            type = JoinType.RIGHT;
        } else if (readIf("LEFT")) {
            read("OUTER");
            type = JoinType.LEFT;
        } else if (readIf("INNER")) {
            type = JoinType.INNER;
        } else {
            break;
        }
        read("JOIN");
        selector = parseSelector();
        selectors.add(selector);
        read("ON");
        JoinCondition on = parseJoinCondition();
        source = type.join(factory, source, selector, on);
    }
    return source;
}
Also used : JoinType(org.apache.jackrabbit.commons.query.qom.JoinType) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector) JoinCondition(javax.jcr.query.qom.JoinCondition)

Example 7 with Selector

use of javax.jcr.query.qom.Selector 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 8 with Selector

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

the class QueryObjectModelFactoryTest method testJoin.

/**
     * Test case for {@link QueryObjectModelFactory#join(Source, Source, String, JoinCondition)}
     */
public void testJoin() throws RepositoryException {
    Selector s1 = qf.selector(ntBase, SELECTOR_NAME1);
    Selector s2 = qf.selector(testNodeType, SELECTOR_NAME1);
    JoinCondition cond = qf.equiJoinCondition(ntBase, jcrPrimaryType, testNodeType, jcrPrimaryType);
    for (Iterator<String> it = JOIN_TYPES.iterator(); it.hasNext(); ) {
        String joinType = it.next();
        Join join = qf.join(s1, s2, joinType, cond);
        assertTrue("Not a selector source", join.getLeft() instanceof Selector);
        assertTrue("Not a selector source", join.getRight() instanceof Selector);
        assertEquals("Wrong join type", joinType, join.getJoinType());
        assertTrue("Not an EquiJoinCondition", join.getJoinCondition() instanceof EquiJoinCondition);
    }
}
Also used : EquiJoinCondition(javax.jcr.query.qom.EquiJoinCondition) Join(javax.jcr.query.qom.Join) Selector(javax.jcr.query.qom.Selector) SameNodeJoinCondition(javax.jcr.query.qom.SameNodeJoinCondition) EquiJoinCondition(javax.jcr.query.qom.EquiJoinCondition) ChildNodeJoinCondition(javax.jcr.query.qom.ChildNodeJoinCondition) JoinCondition(javax.jcr.query.qom.JoinCondition) DescendantNodeJoinCondition(javax.jcr.query.qom.DescendantNodeJoinCondition)

Example 9 with Selector

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

the class QueryObjectModelFactoryTest method testSelector.

/**
     * Test case for {@link QueryObjectModelFactory#selector(String, String)}
     */
public void testSelector() throws RepositoryException {
    Selector selector = qf.selector(ntBase, SELECTOR_NAME1);
    assertEquals("Wrong node type name", ntBase, selector.getNodeTypeName());
    assertEquals("Wrong selector name", SELECTOR_NAME1, selector.getSelectorName());
}
Also used : Selector(javax.jcr.query.qom.Selector)

Example 10 with Selector

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

Aggregations

Selector (javax.jcr.query.qom.Selector)16 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)9 Ordering (javax.jcr.query.qom.Ordering)6 PropertyExistence (javax.jcr.query.qom.PropertyExistence)6 Source (javax.jcr.query.qom.Source)6 Column (javax.jcr.query.qom.Column)5 PropertyValue (javax.jcr.query.qom.PropertyValue)5 Constraint (javax.jcr.query.qom.Constraint)3 BindVariableValue (javax.jcr.query.qom.BindVariableValue)2 JoinCondition (javax.jcr.query.qom.JoinCondition)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ChildNodeJoinCondition (javax.jcr.query.qom.ChildNodeJoinCondition)1 DescendantNodeJoinCondition (javax.jcr.query.qom.DescendantNodeJoinCondition)1 EquiJoinCondition (javax.jcr.query.qom.EquiJoinCondition)1 Join (javax.jcr.query.qom.Join)1 SameNodeJoinCondition (javax.jcr.query.qom.SameNodeJoinCondition)1 JoinType (org.apache.jackrabbit.commons.query.qom.JoinType)1