Search in sources :

Example 1 with Or

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

the class ConstraintSplitter method split.

private void split(ConstraintSplitInfo constraintSplitInfo, Constraint constraint) throws RepositoryException {
    if (constraint instanceof Not) {
        splitNot(constraintSplitInfo, (Not) constraint);
    } else if (constraint instanceof And) {
        And and = (And) constraint;
        split(constraintSplitInfo, and.getConstraint1());
        split(constraintSplitInfo, and.getConstraint2());
    } else if (constraint instanceof Or) {
        if (isReferencingBothSides(getSelectorNames(constraint))) {
            Or or = (Or) constraint;
            //the problem here is when you split an OR that has both condition sides referencing both join sides. 
            // it should split into 2 joins
            constraintSplitInfo.splitOr();
            split(constraintSplitInfo.getLeftInnerConstraints(), or.getConstraint1());
            split(constraintSplitInfo.getRightInnerConstraints(), or.getConstraint2());
        } else {
            splitBySelectors(constraintSplitInfo, constraint, getSelectorNames(constraint));
        }
    } else {
        splitBySelectors(constraintSplitInfo, constraint, getSelectorNames(constraint));
    }
}
Also used : Not(javax.jcr.query.qom.Not) Or(javax.jcr.query.qom.Or) And(javax.jcr.query.qom.And)

Example 2 with Or

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

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

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

the class LuceneQueryFactory method addBooleanConstraint.

protected void addBooleanConstraint(BooleanQuery query, Constraint constraint, Occur occur, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher) throws RepositoryException, IOException {
    if (occur == MUST && constraint instanceof And) {
        And and = (And) constraint;
        addBooleanConstraint(query, and.getConstraint1(), occur, selectorMap, searcher);
        addBooleanConstraint(query, and.getConstraint2(), occur, selectorMap, searcher);
    } else if (occur == SHOULD && constraint instanceof Or) {
        Or or = (Or) constraint;
        addBooleanConstraint(query, or.getConstraint1(), occur, selectorMap, searcher);
        addBooleanConstraint(query, or.getConstraint2(), occur, selectorMap, searcher);
    } else {
        query.add(create(constraint, selectorMap, searcher), occur);
    }
}
Also used : Or(javax.jcr.query.qom.Or) And(javax.jcr.query.qom.And)

Example 5 with Or

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

Aggregations

Or (javax.jcr.query.qom.Or)8 And (javax.jcr.query.qom.And)5 Constraint (javax.jcr.query.qom.Constraint)4 Not (javax.jcr.query.qom.Not)4 PropertyExistence (javax.jcr.query.qom.PropertyExistence)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 ChildNode (javax.jcr.query.qom.ChildNode)1 Comparison (javax.jcr.query.qom.Comparison)1 DescendantNode (javax.jcr.query.qom.DescendantNode)1 FullTextSearch (javax.jcr.query.qom.FullTextSearch)1 SameNode (javax.jcr.query.qom.SameNode)1 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)1 Test (org.junit.Test)1