throws RepositoryException {
Map<String, List<Row>> map = buildRightRowValues(rightRows);
if (JCR_JOIN_TYPE_INNER.equals(type) && !map.isEmpty()) {
List<Row> rows = new ArrayList<Row>();
for (Row leftRow : new RowIterable(leftRows)) {
for (String value : getLeftValues(leftRow)) {
List<Row> matchingRows = map.get(value);
if (matchingRows != null) {
for (Row rightRow : matchingRows) {
rows.add(mergeRow(leftRow, rightRow));
}
}
}
}
return asQueryResult(new RowIteratorAdapter(rows));
}
if (JCR_JOIN_TYPE_LEFT_OUTER.equals(type)) {
// there are no RIGHT dataset values
if (map.isEmpty()) {
// if there are no WHERE conditions, just return everything
// else return an empty set
if (excludingOuterJoinRowsSet == null) {
return asQueryResult(new RowIteratorAdapter(leftRows) {
@Override
public Object next() {
return mergeRow((Row) super.next(), null);
}
});
}
return asQueryResult(new RowIteratorAdapter(
Collections.emptySet()));
}
List<Row> rows = new ArrayList<Row>();
for (Row leftRow : new RowIterable(leftRows)) {
for (String value : getLeftValues(leftRow)) {
List<Row> matchingRows = map.get(value);
if (matchingRows != null) {
for (Row rightRow : matchingRows) {
// I have possible WHERE clauses on the join that I