{
if (!SqlBuilder.fromClauseContainsExpression(
queryFromClause,
leftExpression))
{
FromElement fromElement = new FromElement(
leftExpression.getSql().toString(),
null,
null,
leftExpression.getPreparedStatementReplacements());
queryFromClause.add(fromElement);
}
FromElement fromElement = new FromElement(
rightExpression.getSql().toString(),
joinType,
buildJoinCondition(joinCondition, criteria));
queryFromClause.add(fromElement);
}
else
{
if (SqlBuilder.fromClauseContainsExpression(
queryFromClause,
leftExpression))
{
// We cannot add an explicit join if both tables
// are already present in the from clause
throw new TorqueException(
"Unable to create a" + joinType
+ "because both expressions "
+ leftExpression.getSql()
+ " and " + rightExpression.getSql()
+ " are already in use. "
+ "Try to create an(other) alias.");
}
// now add the join in reverse order
// rightTableName must not be added
// because it is already present
FromElement fromElement = new FromElement(
leftExpression.getSql().toString(),
reverseJoinType(joinType),
buildJoinCondition(joinCondition, criteria));
queryFromClause.add(fromElement);
}