Search in sources :

Example 11 with Constraint

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

the class QomTest method or.

@Test
public void or() throws RepositoryException {
    Constraint c0 = f.propertyExistence("x", "c0");
    Constraint c1 = f.propertyExistence("x", "c1");
    Or or = f.or(c0, c1);
    assertEquals(or.getConstraint1(), c0);
    assertEquals(or.getConstraint2(), c1);
    assertEquals("([x].[c0] IS NOT NULL) OR ([x].[c1] IS NOT NULL)", or.toString());
}
Also used : Or(javax.jcr.query.qom.Or) Constraint(javax.jcr.query.qom.Constraint) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 12 with Constraint

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

the class QOMFormatter method append.

private void append(Not constraint) throws RepositoryException {
    append("NOT ");
    Constraint c = constraint.getConstraint();
    boolean paren = c instanceof And || c instanceof Or;
    if (paren) {
        append("(");
    }
    append(c);
    if (paren) {
        append(")");
    }
}
Also used : Or(javax.jcr.query.qom.Or) Constraint(javax.jcr.query.qom.Constraint) And(javax.jcr.query.qom.And)

Example 13 with Constraint

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

the class QOMFormatter method format.

private String format() throws RepositoryException {
    append("SELECT ");
    append(qom.getColumns());
    append(" FROM ");
    append(qom.getSource());
    Constraint c = qom.getConstraint();
    if (c != null) {
        append(" WHERE ");
        append(c);
    }
    Ordering[] orderings = qom.getOrderings();
    if (orderings.length > 0) {
        append(" ORDER BY ");
        append(orderings);
    }
    return sb.toString();
}
Also used : Constraint(javax.jcr.query.qom.Constraint) Ordering(javax.jcr.query.qom.Ordering)

Example 14 with Constraint

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

the class QOMFormatter method append.

private void append(And constraint) throws RepositoryException {
    String and = "";
    for (Constraint c : Arrays.asList(constraint.getConstraint1(), constraint.getConstraint2())) {
        append(and);
        and = " AND ";
        boolean paren = c instanceof Or || c instanceof Not;
        if (paren) {
            append("(");
        }
        append(c);
        if (paren) {
            append(")");
        }
    }
}
Also used : Not(javax.jcr.query.qom.Not) Or(javax.jcr.query.qom.Or) Constraint(javax.jcr.query.qom.Constraint)

Example 15 with Constraint

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

the class Parser method parseConditionFuntionIf.

private Constraint parseConditionFuntionIf(String functionName) throws RepositoryException {
    Constraint c;
    if ("CONTAINS".equalsIgnoreCase(functionName)) {
        String name = readName();
        if (readIf(".")) {
            if (readIf("*")) {
                read(",");
                c = factory.fullTextSearch(name, null, parseStaticOperand());
            } else {
                String selector = name;
                name = readName();
                read(",");
                c = factory.fullTextSearch(selector, name, parseStaticOperand());
            }
        } else {
            read(",");
            c = factory.fullTextSearch(getOnlySelectorName(name), name, parseStaticOperand());
        }
    } else if ("ISSAMENODE".equalsIgnoreCase(functionName)) {
        String name = readName();
        if (readIf(",")) {
            c = factory.sameNode(name, readPath());
        } else {
            c = factory.sameNode(getOnlySelectorName(name), name);
        }
    } else if ("ISCHILDNODE".equalsIgnoreCase(functionName)) {
        String name = readName();
        if (readIf(",")) {
            c = factory.childNode(name, readPath());
        } else {
            c = factory.childNode(getOnlySelectorName(name), name);
        }
    } else if ("ISDESCENDANTNODE".equalsIgnoreCase(functionName)) {
        String name = readName();
        if (readIf(",")) {
            c = factory.descendantNode(name, readPath());
        } else {
            c = factory.descendantNode(getOnlySelectorName(name), name);
        }
    } else {
        return null;
    }
    read(")");
    return c;
}
Also used : 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