}
}
public static <T> StringBuilder buildSqlSelect(Query<T> query) {
Class<T> clazz = query.getQueriedClass();
JdbcClassInfo info = JdbcClassInfo.getClassInfo(clazz);
List<String> cols = new ArrayList<String>();
List<Field> joinFields = JdbcMappingUtils.getJoinFields(query, info);
if(joinFields==null){
JdbcClassInfo.calculateColumnsAliases(info.allFields, cols, info.tableName, "");
StringBuilder sql =
new StringBuilder("SELECT " + Util.join(cols, ", ") + " FROM " + info.tableName);
return sql;
}
// builds fields from primary class
JdbcClassInfo.calculateColumnsAliases(info.allFields, cols, info.tableName, "");
StringBuilder sql = new StringBuilder(" FROM " + info.tableName);
int i=0;
String alias;
for(Field field: joinFields){
JdbcClassInfo fieldInfo = JdbcClassInfo.getClassInfo(field.getType());
if (!ClassInfo.isModel(field.getType())){
throw new SienaException("Join not possible: Field "+field.getName()+" is not a relation field");
}
alias = fieldInfo.tableName + i++;
fieldInfo.joinFieldAliases.put(field.getName(), alias);