if (!(toAddToFromClause instanceof Column))
{
// toAddToFromClause is a literal Value
return new PreparedStatementPart("?", toAddToFromClause);
}
Column column = (Column) toAddToFromClause;
Column resolvedColumn
= resolveAliasAndAsColumnAndSchema(column, criteria);
String fullTableName
= resolvedColumn.getFullTableName();
if (!StringUtils.equals(
resolvedColumn.getTableName(),
column.getTableName()))
{
// If the tables have an alias, add an "<xxx> <yyy> statement"
// <xxx> AS <yyy> causes problems on oracle
PreparedStatementPart result = new PreparedStatementPart();
result.getSql()
.append(fullTableName)
.append(" ")
.append(column.getTableName());
return result;
}
Object resolvedAlias = criteria.getAliases().get(
resolvedColumn.getTableName());
if (resolvedAlias != null)
{
if (resolvedAlias instanceof Criteria)
{
Criteria subquery = (Criteria) resolvedAlias;
Query renderedSubquery = SqlBuilder.buildQuery(subquery);
PreparedStatementPart result = new PreparedStatementPart();
result.getSql().append("(")
.append(renderedSubquery.toString())
.append(") ")
.append(resolvedColumn.getTableName());
result.getPreparedStatementReplacements().addAll(
renderedSubquery.getPreparedStatementReplacements());
return result;
}
else
{
throw new TorqueException("Table name "
+ resolvedColumn.getTableName()
+ " resolved to an unhandleable class "
+ resolvedAlias.getClass().getName());
}
}