Search in sources :

Example 1 with Not

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

the class QomTest method not.

@Test
public void not() throws RepositoryException {
    Constraint c = f.propertyExistence("x", "c0");
    Not n = f.not(c);
    assertEquals(c, n.getConstraint());
    assertEquals("[x].[c0] IS NOT NULL", c.toString());
    assertEquals("* IS NOT NULL", f.propertyExistence(null, null).toString());
    assertEquals("[s].* IS NOT NULL", f.propertyExistence("s", null).toString());
    assertEquals("[p] IS NOT NULL", f.propertyExistence(null, "p").toString());
    assertEquals("[s].[p] IS NOT NULL", f.propertyExistence("s", "p").toString());
}
Also used : Not(javax.jcr.query.qom.Not) Constraint(javax.jcr.query.qom.Constraint) Test(org.junit.Test)

Example 2 with Not

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

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

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

the class QueryObjectModelFactoryTest method testNot.

/**
 * Test case for {@link QueryObjectModelFactory#not(Constraint)}
 */
public void testNot() throws RepositoryException {
    PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    Not not = qf.not(propExist);
    assertTrue("Not a property existence constraint", not.getConstraint() instanceof PropertyExistence);
}
Also used : Not(javax.jcr.query.qom.Not) PropertyExistence(javax.jcr.query.qom.PropertyExistence)

Example 5 with Not

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

the class LuceneQueryFactory method create.

protected Query create(Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher) throws RepositoryException, IOException {
    if (constraint instanceof And) {
        return getAndQuery((And) constraint, selectorMap, searcher);
    } else if (constraint instanceof Or) {
        return getOrQuery((Or) constraint, selectorMap, searcher);
    } else if (constraint instanceof Not) {
        return getNotQuery((Not) constraint, selectorMap, searcher);
    } else if (constraint instanceof PropertyExistence) {
        return getPropertyExistenceQuery((PropertyExistence) constraint);
    } else if (constraint instanceof Comparison) {
        Comparison c = (Comparison) constraint;
        Transform left = new Transform(c.getOperand1());
        return getComparisonQuery(left.operand, left.transform, c.getOperator(), c.getOperand2(), selectorMap);
    } else if (constraint instanceof FullTextSearch) {
        return getFullTextSearchQuery((FullTextSearch) constraint);
    } else if (constraint instanceof SameNode) {
        SameNode sn = (SameNode) constraint;
        return getNodeIdQuery(UUID, sn.getPath());
    } else if (constraint instanceof ChildNode) {
        ChildNode cn = (ChildNode) constraint;
        return getNodeIdQuery(PARENT, cn.getParentPath());
    } else if (constraint instanceof DescendantNode) {
        DescendantNode dn = (DescendantNode) constraint;
        return getDescendantNodeQuery(dn, searcher);
    } else {
        throw new UnsupportedRepositoryOperationException("Unknown constraint type: " + constraint);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Not(javax.jcr.query.qom.Not) Or(javax.jcr.query.qom.Or) Comparison(javax.jcr.query.qom.Comparison) And(javax.jcr.query.qom.And) DescendantNode(javax.jcr.query.qom.DescendantNode) FullTextSearch(javax.jcr.query.qom.FullTextSearch) SameNode(javax.jcr.query.qom.SameNode) PropertyExistence(javax.jcr.query.qom.PropertyExistence) ChildNode(javax.jcr.query.qom.ChildNode)

Aggregations

Not (javax.jcr.query.qom.Not)6 Or (javax.jcr.query.qom.Or)4 And (javax.jcr.query.qom.And)3 Constraint (javax.jcr.query.qom.Constraint)3 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 Test (org.junit.Test)1