whereClause.append(")");
}
/** Parses the non-compound Condition. */
private boolean parseSimple(Alias alias, SimpleCondition condition) {
Column column = condition.getColumn();
Object operand = condition.getValue();
boolean wasOuter = false;
StringBuffer buffer = whereClause;
if (operand instanceof Selector) {
Selector next = (Selector) operand;
Alias nextAlias = makeAlias(next);
if (next.isOuterJoin()) {
if (next.getCondition() instanceof SimpleCondition) {
parseSimple(nextAlias, (SimpleCondition) next.getCondition());
} else {
wasOuter = true;
}
fromClause.append(" LEFT OUTER JOIN ")
.append(nextAlias.getTable().getName())
.append(" ")
.append(nextAlias.getName())
.append(" ON ");
buffer = fromClause;
} else {
buffer.append("(");
}
buffer.append(alias.getName())
.append(".")
.append(column.getName())
.append(" = ");
// In the usual case this should be nextAlias.primaryKey,
// but in the case of CONTAINS it should be nextAlias.foreignKey.
buffer.append(nextAlias.getName())
.append(".")
.append(nextAlias.getJoinColumn().getName());
// Because Many-to-Many operations can cause multiple
// copies, set the distinct flag.
if (condition.getOperator() == Operator.CONTAINS) {
distinct = true;
}
if (!next.isOuterJoin()) {
parse(nextAlias, next);
buffer.append(")");
}
} else {
whereClause.append("(");
whereClause.append(alias.getName())
.append(".")
.append(column.getName());
parseOperand(condition.getOperator(), operand);
whereClause.append(")");
}
return wasOuter;
}