@Override protected ConstraintBuilder setConstraint( Constraint constraint ) { Comparison comparison = (Comparison)constraint; return delegate.setConstraint(new Comparison(new UpperCase(comparison.getOperand1()), comparison.operator(), comparison.getOperand2())); } }
@Override protected boolean indexAppliesTo( Comparison constraint ) { if (QueryObjectModelConstants.JCR_OPERATOR_LIKE.equals(constraint.getOperator())) { // Our indexes don't handle LIKE operations ... return false; } return super.indexAppliesTo(constraint); }
@Override public void visit( Comparison obj ) { // The dynamic operand itself will be visited by the validator as it walks the comparison object. verifyComparison(obj.getOperand1(), obj.operator(), obj.getOperand2()); }
protected boolean indexAppliesTo( Comparison constraint ) { return applies(constraint.operator()) && applies(constraint.getOperand1()); }
protected Comparison comparison( DynamicOperand left, Operator operator, StaticOperand right ) { return new Comparison(left, operator, right); }
@Override public void visit( Comparison comparison ) { strategy.visit(comparison); enqueue(comparison.getOperand1()); enqueue(comparison.getOperand2()); visitNext(); }
PlanNode source = new PlanNode(Type.SOURCE, select3, selector("t1")); source.setProperty(Property.SOURCE_NAME, selector("t1")); select1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c2"), Operator.EQUAL_TO, new Literal(100L))); select2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c1"), Operator.LESS_THAN_OR_EQUAL_TO, new Literal(3L))); select3.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c1"), Operator.GREATER_THAN_OR_EQUAL_TO, new Literal(1L))); assertThat(newSelect.getParent(), is(sameInstance(project))); Between between = newSelect.getProperty(Property.SELECT_CRITERIA, Between.class); assertThat(between.getOperand(), is(select2.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand1())); assertThat(between.getLowerBound(), is(select3.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand2())); assertThat(between.getUpperBound(), is(select2.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand2())); assertThat(between.isLowerBoundIncluded(), is(true)); assertThat(between.isUpperBoundIncluded(), is(true));
@Override protected OperationBuilder<T> apply( Comparison comparison, boolean negated ) { StaticOperand operand = comparison.getOperand2(); Operator op = comparison.operator(); if (negated) op = op.not();
/** * Compare the values used in the two comparisons * * @param context the query context; may not be null * @param comparison1 the first comparison object; may not be null * @param comparison2 the second comparison object; may not be null * @return 0 if the values are the same, less than 0 if the first comparison's value is less than the second's, or greater * than 0 if the first comparison's value is greater than the second's */ protected int compareStaticOperands( QueryContext context, Comparison comparison1, Comparison comparison2 ) { Object value1 = getValue(context, comparison1.getOperand2()); Object value2 = getValue(context, comparison2.getOperand2()); return ValueComparators.OBJECT_COMPARATOR.compare(value1, value2); }
@Override public String getOperator() { switch (operator()) { case EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO; case GREATER_THAN: return QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN; case GREATER_THAN_OR_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO; case LESS_THAN: return QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN; case LESS_THAN_OR_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO; case LIKE: return QueryObjectModelConstants.JCR_OPERATOR_LIKE; case NOT_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO; } assert false; return null; }
@Override public void visit( Comparison obj ) { // The dynamic operand itself will be visited by the validator as it walks the comparison object. verifyComparison(obj.getOperand1(), obj.operator(), obj.getOperand2()); }
protected Comparison comparison( DynamicOperand left, Operator operator, StaticOperand right ) { return new Comparison(left, operator, right); }
@Override public void visit( Comparison comparison ) { strategy.visit(comparison); enqueue(comparison.getOperand1()); enqueue(comparison.getOperand2()); visitNext(); }
PlanNode source = new PlanNode(Type.SOURCE, select3, selector("t1")); source.setProperty(Property.SOURCE_NAME, selector("t1")); select1.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c2"), Operator.EQUAL_TO, new Literal(100L))); select2.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c1"), Operator.LESS_THAN, new Literal(3L))); select3.setProperty(Property.SELECT_CRITERIA, new Comparison(new PropertyValue(selector("t1"), "c1"), Operator.GREATER_THAN, new Literal(1L))); assertThat(newSelect.getParent(), is(sameInstance(project))); Between between = newSelect.getProperty(Property.SELECT_CRITERIA, Between.class); assertThat(between.getOperand(), is(select2.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand1())); assertThat(between.getLowerBound(), is(select3.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand2())); assertThat(between.getUpperBound(), is(select2.getProperty(Property.SELECT_CRITERIA, Comparison.class).getOperand2())); assertThat(between.isLowerBoundIncluded(), is(false)); assertThat(between.isUpperBoundIncluded(), is(false));
protected boolean indexAppliesTo( Comparison constraint ) { return applies(constraint.operator()) && applies(constraint.getOperand1()); }
@Override protected OperationBuilder<T> apply( Comparison comparison, boolean negated ) { StaticOperand operand = comparison.getOperand2(); Operator op = comparison.operator(); if (negated) op = op.not();
/** * Compare the values used in the two comparisons * * @param context the query context; may not be null * @param comparison1 the first comparison object; may not be null * @param comparison2 the second comparison object; may not be null * @return 0 if the values are the same, less than 0 if the first comparison's value is less than the second's, or greater * than 0 if the first comparison's value is greater than the second's */ protected int compareStaticOperands( QueryContext context, Comparison comparison1, Comparison comparison2 ) { Object value1 = getValue(context, comparison1.getOperand2()); Object value2 = getValue(context, comparison2.getOperand2()); return ValueComparators.OBJECT_COMPARATOR.compare(value1, value2); }
@Override public String getOperator() { switch (operator()) { case EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO; case GREATER_THAN: return QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN; case GREATER_THAN_OR_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO; case LESS_THAN: return QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN; case LESS_THAN_OR_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO; case LIKE: return QueryObjectModelConstants.JCR_OPERATOR_LIKE; case NOT_EQUAL_TO: return QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO; } assert false; return null; }
@Override protected ConstraintBuilder setConstraint( Constraint constraint ) { Comparison comparison = (Comparison)constraint; return delegate.setConstraint(new Comparison(new LowerCase(comparison.getOperand1()), comparison.operator(), comparison.getOperand2())); } }
@Override public void visit( Comparison comparison ) { comparison.getOperand1().accept(this); append(' ').append(comparison.operator().symbol()).append(' '); comparison.getOperand2().accept(this); }