Search in sources :

Example 1 with And

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

the class QueryObjectModelFactoryTest method testAnd.

/**
     * Test case for {@link QueryObjectModelFactory#and(Constraint, Constraint)}
     */
public void testAnd() throws RepositoryException {
    PropertyExistence c1 = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
    PropertyExistence c2 = qf.propertyExistence(SELECTOR_NAME1, propertyName2);
    And and = qf.and(c1, c2);
    assertTrue("Not a PropertyExistence constraint", and.getConstraint1() instanceof PropertyExistence);
    assertTrue("Not a PropertyExistence constraint", and.getConstraint2() instanceof PropertyExistence);
}
Also used : And(javax.jcr.query.qom.And) PropertyExistence(javax.jcr.query.qom.PropertyExistence)

Example 2 with And

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

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

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

the class LuceneQueryFactory method mapConstraintToQueryAndFilter.

protected Predicate mapConstraintToQueryAndFilter(QueryPair query, Constraint constraint, Map<String, NodeType> selectorMap, JackrabbitIndexSearcher searcher, IndexReader reader) throws RepositoryException, IOException {
    Predicate filter = Predicate.TRUE;
    if (constraint instanceof And) {
        And and = (And) constraint;
        filter = mapConstraintToQueryAndFilter(query, and.getConstraint1(), selectorMap, searcher, reader);
        Predicate other = mapConstraintToQueryAndFilter(query, and.getConstraint2(), selectorMap, searcher, reader);
        if (filter == Predicate.TRUE) {
            filter = other;
        } else if (other != Predicate.TRUE) {
            filter = Predicates.and(filter, other);
        }
    } else if (constraint instanceof Comparison) {
        Comparison c = (Comparison) constraint;
        Transform transform = new Transform(c.getOperand1());
        DynamicOperand left = transform.operand;
        final String operator = c.getOperator();
        StaticOperand right = c.getOperand2();
        if (left instanceof Length || left instanceof FullTextSearchScore || (((!JCR_OPERATOR_EQUAL_TO.equals(operator) && !JCR_OPERATOR_LIKE.equals(operator)) || transform.transform != TRANSFORM_NONE) && (left instanceof NodeName || left instanceof NodeLocalName))) {
            try {
                int type = PropertyType.UNDEFINED;
                if (left instanceof Length) {
                    type = PropertyType.LONG;
                } else if (left instanceof FullTextSearchScore) {
                    type = PropertyType.DOUBLE;
                }
                final DynamicOperand operand = c.getOperand1();
                final Value value = evaluator.getValue(right, type);
                filter = new RowPredicate() {

                    @Override
                    protected boolean evaluate(Row row) throws RepositoryException {
                        return new ValueComparator().evaluate(operator, evaluator.getValue(operand, row), value);
                    }
                };
            } catch (ValueFormatException e) {
                throw new InvalidQueryException(e);
            }
        } else {
            Query cq = getComparisonQuery(left, transform.transform, operator, right, selectorMap);
            query.subQuery.add(cq, MUST);
        }
    } else if (constraint instanceof DescendantNode) {
        final DescendantNode descendantNode = (DescendantNode) constraint;
        Query context = getNodeIdQuery(UUID, descendantNode.getAncestorPath());
        query.mainQuery = new DescendantSelfAxisQuery(context, query.subQuery, false);
    } else {
        query.subQuery.add(create(constraint, selectorMap, searcher), MUST);
    }
    return filter;
}
Also used : Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) DynamicOperand(javax.jcr.query.qom.DynamicOperand) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) ValueComparator(org.apache.jackrabbit.core.query.lucene.join.ValueComparator) Predicate(org.apache.jackrabbit.commons.predicate.Predicate) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) NodeLocalName(javax.jcr.query.qom.NodeLocalName) RowPredicate(org.apache.jackrabbit.commons.predicate.RowPredicate) Comparison(javax.jcr.query.qom.Comparison) Length(javax.jcr.query.qom.Length) And(javax.jcr.query.qom.And) DescendantNode(javax.jcr.query.qom.DescendantNode) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ValueFormatException(javax.jcr.ValueFormatException) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) SelectorRow(org.apache.jackrabbit.core.query.lucene.join.SelectorRow) Row(javax.jcr.query.Row) InvalidQueryException(javax.jcr.query.InvalidQueryException)

Example 5 with And

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

Aggregations

And (javax.jcr.query.qom.And)8 Or (javax.jcr.query.qom.Or)5 Constraint (javax.jcr.query.qom.Constraint)3 Not (javax.jcr.query.qom.Not)3 Comparison (javax.jcr.query.qom.Comparison)2 DescendantNode (javax.jcr.query.qom.DescendantNode)2 PropertyExistence (javax.jcr.query.qom.PropertyExistence)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 Value (javax.jcr.Value)1 ValueFormatException (javax.jcr.ValueFormatException)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1 Row (javax.jcr.query.Row)1 ChildNode (javax.jcr.query.qom.ChildNode)1 DynamicOperand (javax.jcr.query.qom.DynamicOperand)1 FullTextSearch (javax.jcr.query.qom.FullTextSearch)1 FullTextSearchScore (javax.jcr.query.qom.FullTextSearchScore)1 Length (javax.jcr.query.qom.Length)1 NodeLocalName (javax.jcr.query.qom.NodeLocalName)1 NodeName (javax.jcr.query.qom.NodeName)1 PropertyValue (javax.jcr.query.qom.PropertyValue)1