Search in sources :

Example 21 with Constraint

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

the class ConstraintSplitter method splitNot.

private void splitNot(ConstraintSplitInfo constraintSplitInfo, Not not) throws RepositoryException {
    Constraint constraint = not.getConstraint();
    if (constraint instanceof Not) {
        split(constraintSplitInfo, ((Not) constraint).getConstraint());
    } else if (constraint instanceof And) {
        And and = (And) constraint;
        split(constraintSplitInfo, factory.or(factory.not(and.getConstraint1()), factory.not(and.getConstraint2())));
    } else if (constraint instanceof Or) {
        Or or = (Or) constraint;
        split(constraintSplitInfo, factory.and(factory.not(or.getConstraint1()), factory.not(or.getConstraint2())));
    } else {
        splitBySelectors(constraintSplitInfo, not, getSelectorNames(constraint));
    }
}
Also used : Not(javax.jcr.query.qom.Not) Or(javax.jcr.query.qom.Or) Constraint(javax.jcr.query.qom.Constraint) And(javax.jcr.query.qom.And)

Example 22 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit-oak by apache.

the class QomTest method jcrNameConversion.

@Test
public void jcrNameConversion() throws RepositoryException {
    assertEquals("[nt:base]", f.column(null, NodeType.NT_BASE, null).toString());
    assertEquals("[s1].[nt:base] = [s2].[nt:base]", f.equiJoinCondition("s1", NodeType.NT_BASE, "s2", NodeType.NT_BASE).toString());
    assertEquals("CONTAINS([nt:base], null)", f.fullTextSearch(null, NodeType.NT_BASE, null).toString());
    assertEquals("CAST('nt:base' AS NAME)", f.literal(vf.createValue(NodeType.NT_BASE, PropertyType.NAME)).toString());
    assertEquals("[nt:base] IS NOT NULL", f.propertyExistence(null, NodeType.NT_BASE).toString());
    assertEquals("[nt:base]", f.propertyValue(null, NodeType.NT_BASE).toString());
    assertEquals("[nt:base]", f.selector(NodeType.NT_BASE, null).toString());
    Source source1 = f.selector(NodeType.NT_BASE, "selector");
    Column[] columns = new Column[] { f.column("selector", null, null) };
    Constraint constraint2 = f.childNode("selector", "/");
    QueryObjectModel qom = f.createQuery(source1, constraint2, null, columns);
    assertEquals("select [selector].* from " + "[nt:base] AS [selector] " + "where ISCHILDNODE([selector], [/])", qom.toString());
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) Source(javax.jcr.query.qom.Source) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 23 with Constraint

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

the class SQL2PathEscapingTest method testGetChildrenApiStatement.

/**
     * the statement behind the api should be consistent, and return a similar
     * query. in our case it should escape the paths that have spaces in them by
     * enclosing them in single quotes
     * 
     * @throws Exception
     */
public void testGetChildrenApiStatement() throws Exception {
    QueryObjectModelFactory qomf = qm.getQOMFactory();
    Source source1 = qomf.selector(NodeType.NT_BASE, "selector");
    Column[] columns = new Column[] { qomf.column("selector", null, null) };
    Constraint constraint2 = qomf.childNode("selector", n1.getPath());
    QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns);
    checkResult(executeSQL2Query(qom.getStatement()), 2);
}
Also used : Column(javax.jcr.query.qom.Column) Constraint(javax.jcr.query.qom.Constraint) QueryObjectModel(javax.jcr.query.qom.QueryObjectModel) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) Source(javax.jcr.query.qom.Source)

Example 24 with Constraint

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

the class Parser method parseCondition.

private Constraint parseCondition(DynamicOperand left) throws RepositoryException {
    Constraint c;
    if (readIf("=")) {
        c = Operator.EQ.comparison(factory, left, parseStaticOperand());
    } else if (readIf("<>")) {
        c = Operator.NE.comparison(factory, left, parseStaticOperand());
    } else if (readIf("<")) {
        c = Operator.LT.comparison(factory, left, parseStaticOperand());
    } else if (readIf(">")) {
        c = Operator.GT.comparison(factory, left, parseStaticOperand());
    } else if (readIf("<=")) {
        c = Operator.LE.comparison(factory, left, parseStaticOperand());
    } else if (readIf(">=")) {
        c = Operator.GE.comparison(factory, left, parseStaticOperand());
    } else if (readIf("LIKE")) {
        c = Operator.LIKE.comparison(factory, left, parseStaticOperand());
    } else if (readIf("IS")) {
        boolean not = readIf("NOT");
        read("NULL");
        if (!(left instanceof PropertyValue)) {
            throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
        }
        PropertyValue p = (PropertyValue) left;
        c = getPropertyExistence(p);
        if (!not) {
            c = factory.not(c);
        }
    } else if (readIf("NOT")) {
        if (readIf("IS")) {
            read("NULL");
            if (!(left instanceof PropertyValue)) {
                throw new RepositoryException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName());
            }
            PropertyValue pv = (PropertyValue) left;
            c = getPropertyExistence(pv);
        } else {
            read("LIKE");
            c = factory.not(Operator.LIKE.comparison(factory, left, parseStaticOperand()));
        }
    } else {
        throw getSyntaxError();
    }
    return c;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) PropertyValue(javax.jcr.query.qom.PropertyValue) RepositoryException(javax.jcr.RepositoryException)

Example 25 with Constraint

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

the class QueryObjectModelFactoryImpl method createQuery.

/**
     * Creates a query with one or more selectors.
     * <p>
     * If <code>source</code> is a selector, that selector is the <i>default
     * selector</i> of the query.  Otherwise the query does not have a default
     * selector.
     *
     * @param source     the node-tuple source; non-null
     * @param constraint the constraint, or null if none
     * @param orderings  zero or more orderings; null is equivalent to a
     *                   zero-length array
     * @param columns    the columns; null is equivalent to a zero-length array
     * @return the query; non-null
     * @throws javax.jcr.query.InvalidQueryException
     *                                       if the query is invalid
     * @throws javax.jcr.RepositoryException if the operation otherwise fails
     */
public QueryObjectModel createQuery(Source source, Constraint constraint, Ordering[] orderings, Column[] columns) throws InvalidQueryException, RepositoryException {
    if (source == null) {
        throw new InvalidQueryException("source must not be null");
    }
    if (!(source instanceof SourceImpl)) {
        throw new RepositoryException("Unknown Source implementation");
    }
    if (constraint != null && !(constraint instanceof ConstraintImpl)) {
        throw new RepositoryException("Unknown Constraint implementation");
    }
    OrderingImpl[] ords;
    if (orderings != null) {
        ords = new OrderingImpl[orderings.length];
        for (int i = 0; i < orderings.length; i++) {
            if (!(orderings[i] instanceof OrderingImpl)) {
                throw new RepositoryException("Unknown Ordering implementation");
            }
            ords[i] = (OrderingImpl) orderings[i];
        }
    } else {
        ords = OrderingImpl.EMPTY_ARRAY;
    }
    ColumnImpl[] cols;
    if (columns != null) {
        cols = new ColumnImpl[columns.length];
        for (int i = 0; i < columns.length; i++) {
            if (!(columns[i] instanceof ColumnImpl)) {
                throw new RepositoryException("Unknown Column implementation");
            }
            cols[i] = (ColumnImpl) columns[i];
        }
    } else {
        cols = ColumnImpl.EMPTY_ARRAY;
    }
    QueryObjectModelTree qomTree = new QueryObjectModelTree(resolver, (SourceImpl) source, (ConstraintImpl) constraint, ords, cols);
    return createQuery(qomTree);
}
Also used : RepositoryException(javax.jcr.RepositoryException) InvalidQueryException(javax.jcr.query.InvalidQueryException) Constraint(javax.jcr.query.qom.Constraint)

Aggregations

Constraint (javax.jcr.query.qom.Constraint)25 Row (javax.jcr.query.Row)7 Column (javax.jcr.query.qom.Column)6 ArrayList (java.util.ArrayList)5 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)5 Test (org.junit.Test)5 Or (javax.jcr.query.qom.Or)4 Ordering (javax.jcr.query.qom.Ordering)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 Source (javax.jcr.query.qom.Source)4 HashSet (java.util.HashSet)3 And (javax.jcr.query.qom.And)3 Not (javax.jcr.query.qom.Not)3 PropertyValue (javax.jcr.query.qom.PropertyValue)3 TreeSet (java.util.TreeSet)2 RepositoryException (javax.jcr.RepositoryException)2 QueryResult (javax.jcr.query.QueryResult)2 BindVariableValue (javax.jcr.query.qom.BindVariableValue)2 QueryObjectModelFactory (javax.jcr.query.qom.QueryObjectModelFactory)2 Selector (javax.jcr.query.qom.Selector)2