Search in sources :

Example 6 with Source

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

the class QueryObjectModelFactoryTest method testCreateQueryFromSource.

public void testCreateQueryFromSource() throws RepositoryException {
    Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
    QueryObjectModel qom = qf.createQuery(selector, null, null, null);
    assertTrue("Not a selector source", qom.getSource() instanceof Selector);
    assertNull("Constraint must be null", qom.getConstraint());
    assertEquals("Wrong size of orderings", 0, qom.getOrderings().length);
    assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
Also used : QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Source(javax.jcr.query.qom.Source) Selector(javax.jcr.query.qom.Selector)

Example 7 with Source

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

the class QueryObjectModelFactoryTest method testCreateQueryFromSourceWithConstraint.

public void testCreateQueryFromSourceWithConstraint() throws RepositoryException {
    Source selector = qf.selector(testNodeType, SELECTOR_NAME1);
    PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    QueryObjectModel qom = qf.createQuery(selector, propExist, null, 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", 0, qom.getOrderings().length);
    assertEquals("Wrong size of columns", 0, qom.getColumns().length);
}
Also used : 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 Source

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

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

the class Parser method createQueryObjectModel.

/**
 * Parse a JCR-SQL2 query and return the query object model
 *
 * @param query the query string
 * @return the query object model
 * @throws RepositoryException if parsing failed
 */
public QueryObjectModel createQueryObjectModel(String query) throws RepositoryException {
    initialize(query);
    selectors = new ArrayList<Selector>();
    expected = new ArrayList<String>();
    bindVariables = new HashMap<String, BindVariableValue>();
    read();
    read("SELECT");
    int columnParseIndex = parseIndex;
    ArrayList<ColumnOrWildcard> list = parseColumns();
    read("FROM");
    Source source = parseSource();
    Column[] columnArray = resolveColumns(columnParseIndex, list);
    Constraint constraint = null;
    if (readIf("WHERE")) {
        constraint = parseConstraint();
    }
    Ordering[] orderings = null;
    if (readIf("ORDER")) {
        read("BY");
        orderings = parseOrder();
    }
    if (currentToken.length() > 0) {
        throw getSyntaxError("<end>");
    }
    return factory.createQuery(source, constraint, orderings, columnArray);
}
Also used : BindVariableValue(javax.jcr.query.qom.BindVariableValue) Constraint(javax.jcr.query.qom.Constraint) Constraint(javax.jcr.query.qom.Constraint) Source(javax.jcr.query.qom.Source) Column(javax.jcr.query.qom.Column) Ordering(javax.jcr.query.qom.Ordering) Selector(javax.jcr.query.qom.Selector)

Example 10 with Source

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

Aggregations

Source (javax.jcr.query.qom.Source)10 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)7 Selector (javax.jcr.query.qom.Selector)6 Column (javax.jcr.query.qom.Column)5 Constraint (javax.jcr.query.qom.Constraint)4 Ordering (javax.jcr.query.qom.Ordering)3 PropertyExistence (javax.jcr.query.qom.PropertyExistence)3 PropertyValue (javax.jcr.query.qom.PropertyValue)2 QueryObjectModelFactory (javax.jcr.query.qom.QueryObjectModelFactory)2 Test (org.junit.Test)2 BindVariableValue (javax.jcr.query.qom.BindVariableValue)1 ChildNodeJoinCondition (javax.jcr.query.qom.ChildNodeJoinCondition)1 Join (javax.jcr.query.qom.Join)1 JoinCondition (javax.jcr.query.qom.JoinCondition)1 JoinType (org.apache.jackrabbit.commons.query.qom.JoinType)1