Search in sources :

Example 1 with Selector

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

the class QueryObjectModelFactoryTest method testCreateQueryWithConstraint.

public void testCreateQueryWithConstraint() throws RepositoryException {
    Selector 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) Selector(javax.jcr.query.qom.Selector)

Example 2 with Selector

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

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

the class Parser method resolveColumns.

private Column[] resolveColumns(int columnParseIndex, ArrayList<ColumnOrWildcard> list) throws RepositoryException {
    int oldParseIndex = parseIndex;
    // set the parse index to the column list, to get a more meaningful error message
    // if something is wrong
    this.parseIndex = columnParseIndex;
    try {
        ArrayList<Column> columns = new ArrayList<Column>();
        for (ColumnOrWildcard c : list) {
            if (c.propertyName == null) {
                for (Selector selector : selectors) {
                    if (c.selectorName == null || c.selectorName.equals(selector.getSelectorName())) {
                        Column column = factory.column(selector.getSelectorName(), null, null);
                        columns.add(column);
                    }
                }
            } else {
                Column column;
                if (c.selectorName != null) {
                    column = factory.column(c.selectorName, c.propertyName, c.columnName);
                } else if (c.columnName != null) {
                    column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.columnName);
                } else {
                    column = factory.column(getOnlySelectorName(c.propertyName), c.propertyName, c.propertyName);
                }
                columns.add(column);
            }
        }
        Column[] array = new Column[columns.size()];
        columns.toArray(array);
        return array;
    } finally {
        this.parseIndex = oldParseIndex;
    }
}
Also used : Column(javax.jcr.query.qom.Column) ArrayList(java.util.ArrayList) Constraint(javax.jcr.query.qom.Constraint) Selector(javax.jcr.query.qom.Selector)

Example 4 with Selector

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

Example 5 with Selector

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

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