for (int i = 0; i < leftFields.length; i++) {
conditions.add(leftFields[i].equal((Field) rightFields[i]));
}
Condition result = new CombinedCondition(Operator.AND, conditions);
if (comparator == NOT_EQUALS) {
result = result.not();
}
return (QueryPartInternal) result;
}
// Ordering comparison predicate simulation
else if (asList(GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL).contains(comparator) &&
asList(DERBY, CUBRID, FIREBIRD, SQLITE).contains(dialect.family())) {
// The order component of the comparator (stripping the equal component)
Comparator order
= (comparator == GREATER) ? GREATER
: (comparator == GREATER_OR_EQUAL) ? GREATER
: (comparator == LESS) ? LESS
: (comparator == LESS_OR_EQUAL) ? LESS
: null;
// [#2658] The factored order component of the comparator (enforcing the equal component)
Comparator factoredOrder
= (comparator == GREATER) ? GREATER_OR_EQUAL
: (comparator == GREATER_OR_EQUAL) ? GREATER_OR_EQUAL
: (comparator == LESS) ? LESS_OR_EQUAL
: (comparator == LESS_OR_EQUAL) ? LESS_OR_EQUAL
: null;
// Whether the comparator has an equal component
boolean equal
= (comparator == GREATER_OR_EQUAL)
||(comparator == LESS_OR_EQUAL);
// The following algorithm simulates the equivalency of these expressions:
// (A, B, C) > (X, Y, Z)
// (A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z)
List<Condition> outer = new ArrayList<Condition>();
Field<?>[] leftFields = left.fields();
Field<?>[] rightFields = right.fields();
for (int i = 0; i < leftFields.length; i++) {
List<Condition> inner = new ArrayList<Condition>();
for (int j = 0; j < i; j++) {
inner.add(leftFields[j].equal((Field) rightFields[j]));
}
inner.add(leftFields[i].compare(order, (Field) rightFields[i]));
outer.add(new CombinedCondition(Operator.AND, inner));
}
if (equal) {
outer.add(new RowCondition(left, right, Comparator.EQUALS));
}
Condition result = new CombinedCondition(Operator.OR, outer);
// [#2658] For performance reasons, an additional, redundant
// predicate is factored out to favour the application of range
// scans as the topmost predicate is AND-connected, not
// OR-connected: