/** * Walk the supplied constraint to extract a list of the constraints that can be AND-ed together. For example, given the * constraint tree ((C1 AND C2) AND (C3 OR C4)), this method would result in a list of three separate criteria: [C1,C2,(C3 OR * C4)]. The resulting <code>andConstraints</code> list will contain Constraint objects that all must be true. * * @param constraint the input constraint * @param andableConstraints the collection into which all non-{@link And AND} constraints should be placed */ protected void separateAndConstraints(Constraint constraint, List<Constraint> andableConstraints) { if (constraint == null) { return; } if (constraint instanceof And) { And and = (And)constraint; separateAndConstraints(and.getLeft(), andableConstraints); separateAndConstraints(and.getRight(), andableConstraints); } else { andableConstraints.add(constraint); } } }
/** * @see org.xcmis.search.QueryObjectModelVisitor#visit(org.xcmis.search.model.constraint.And) */ public void visit(And node) throws VisitException { // TODO check selector size; // final int selectors = node.getSelectorsNames().size(); final int selectors = 1; if (selectors == 1) { // Operators will push query to stack Visitors.visit(node.getLeft(), this); Visitors.visit(node.getRight(), this); BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.add((Query)queryBuilderStack.pop(), BooleanClause.Occur.MUST); booleanQuery.add((Query)queryBuilderStack.pop(), BooleanClause.Occur.MUST); queryBuilderStack.push(booleanQuery); } else { //TODO check throw new UnsupportedOperationException("More then one selector used"); } }
/** * {@inheritDoc} * @throws VisitException if exception occurs * * @see QueryObjectModelVisitor#visit(And) */ public void visit(And and) throws VisitException { strategy.visit(and); enqueue(and.getLeft()); enqueue(and.getRight()); visitNext(); }
/** * {@inheritDoc} * @throws VisitException if exception occurs * * @see QueryObjectModelVisitor#visit(And) */ public void visit(And and) throws VisitException { append('('); and.getLeft().accept(this); append(" AND "); and.getRight().accept(this); append(')'); }