ListIterator<Join> iter = joins.listIterator();
while (iter.hasNext()) {
Join next = iter.next();
Join replacement = null;
if (usesSelector(next, selector1)) {
Source right = joinableSources.getSelectors().get(selector2.name());
replacement = new Join(next, JoinType.INNER, right, joinCondition);
} else if (usesSelector(next, selector2)) {
Source left = joinableSources.getSelectors().get(selector1.name());
replacement = new Join(left, JoinType.INNER, next, joinCondition);
}
if (replacement != null) {
iter.previous();
iter.remove();
joins.add(replacement);
found = true;
break;
}
}
if (!found) {
// Nothing matched, so add a new join ...
Source left = joinableSources.getSelectors().get(selector1.name());
Source right = joinableSources.getSelectors().get(selector2.name());
if (left == null) {
Position pos = joinableSources.getJoinCriteriaPosition();
String msg = JcrI18n.selectorUsedInEquiJoinCriteriaDoesNotExistInQuery.text(selector1.name(),
pos.getLine(),
pos.getColumn());