use of org.apache.cayenne.access.sqlbuilder.OrderingNodeBuilder in project cayenne by apache.
the class OrderingStage method processOrdering.
private void processOrdering(QualifierTranslator qualifierTranslator, TranslatorContext context, Ordering ordering) {
Expression exp = ordering.getSortSpec();
Node translatedNode = qualifierTranslator.translate(exp);
NodeBuilder nodeBuilder = node(translatedNode);
if (ordering.isCaseInsensitive()) {
nodeBuilder = function("UPPER", nodeBuilder);
}
// If query is DISTINCT then we need to add all ORDER BY clauses as result columns
if (!context.isDistinctSuppression()) {
// TODO: need to check duplicates?
// need UPPER() function here too, as some DB expect exactly the same expression in select and in ordering
ResultNodeDescriptor descriptor = context.addResultNode(nodeBuilder.build().deepCopy());
if (exp instanceof ASTAggregateFunctionCall) {
descriptor.setAggregate(true);
}
}
OrderingNodeBuilder orderingNodeBuilder = order(nodeBuilder);
if (ordering.isDescending()) {
orderingNodeBuilder.desc();
}
context.getSelectBuilder().orderBy(orderingNodeBuilder);
}
Aggregations