protected Constraint rewriteCriteria( QueryContext context,
Constraint constraint ) {
if (constraint instanceof And) {
And and = (And)constraint;
Constraint oldLeft = and.left();
Constraint oldRight = and.right();
Constraint newLeft = rewriteCriteria(context, oldLeft);
Constraint newRight = rewriteCriteria(context, oldRight);
if (newRight != oldRight) {
// The right side is path-oriented ...
if (newLeft != oldLeft) {
// The left is too, so create a new And constraint to signal that it's path oriented ...
return new And(newLeft, newRight);
}
// Only the right is, so swap the order ...
return new And(newRight, newLeft);
}
// Neither are path-oriented ...
return and;
}
if (constraint instanceof Or) {
Or or = (Or)constraint;
Constraint oldLeft = or.left();
Constraint oldRight = or.right();
Constraint newLeft = rewriteCriteria(context, oldLeft);
Constraint newRight = rewriteCriteria(context, oldRight);
if (newRight != oldRight) {
// The right side is path-oriented ...
if (newLeft != oldLeft) {
// The left is too, so create a new Or constraint to signal that it's path oriented ...
return new Or(newLeft, newRight);
}
// Only the right is, so swap the order ...
return new Or(newRight, newLeft);
}
// Neither are path-oriented ...
return or;
}
if (constraint instanceof Not) {
Not not = (Not)constraint;
Constraint oldWrapped = not.getConstraint();
Constraint newWrapped = rewriteCriteria(context, oldWrapped);
if (newWrapped != oldWrapped) {
// The wrapped constraint is path-oriented, so create a new Not to signal it ...
return new Not(newWrapped);
}
return not;