Appendable mainBuffer = this.out;
try {
while (it.hasNext()) {
Ordering ord = it.next();
// reset buffer to collect SQL for the single column, that we'll be reusing
this.out = new StringBuilder();
if (ord.isCaseInsensitive()) {
out.append("UPPER(");
}
Expression exp = ord.getSortSpec();
if (exp.getType() == Expression.OBJ_PATH) {
appendObjPath(exp);
}
else if (exp.getType() == Expression.DB_PATH) {
appendDbPath(exp);
}
else {
throw new CayenneRuntimeException("Unsupported ordering expression: "
+ exp);
}
// Close UPPER() modifier
if (ord.isCaseInsensitive()) {
out.append(")");
}
String columnSQL = out.toString();
mainBuffer.append(columnSQL);
orderByColumnList.add(columnSQL);
// "ASC" is a noop, omit it from the query
if (!ord.isAscending()) {
mainBuffer.append(" DESC");
}
if (it.hasNext()) {
mainBuffer.append(", ");