Search in sources :

Example 6 with Constraint

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

the class SQL2PathEscapingTest method testGetChildrenApiDirect.

/**
     * will build a query directly via the api using a spaced path
     * 
     * @throws Exception
     */
public void testGetChildrenApiDirect() 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(qom.execute(), 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 7 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 8 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 9 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 10 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