Search in sources :

Example 1 with ASTAggregateFunctionCall

use of org.apache.cayenne.exp.parser.ASTAggregateFunctionCall 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);
}
Also used : Expression(org.apache.cayenne.exp.Expression) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) ASTAggregateFunctionCall(org.apache.cayenne.exp.parser.ASTAggregateFunctionCall) NodeBuilder(org.apache.cayenne.access.sqlbuilder.NodeBuilder) OrderingNodeBuilder(org.apache.cayenne.access.sqlbuilder.OrderingNodeBuilder) OrderingNodeBuilder(org.apache.cayenne.access.sqlbuilder.OrderingNodeBuilder)

Example 2 with ASTAggregateFunctionCall

use of org.apache.cayenne.exp.parser.ASTAggregateFunctionCall in project cayenne by apache.

the class DefaultSelectTranslator method isAggregate.

private boolean isAggregate(Property<?> property) {
    final boolean[] isAggregate = new boolean[1];
    Expression exp = property.getExpression();
    exp.traverse(new TraversalHelper() {

        @Override
        public void startNode(Expression node, Expression parentNode) {
            if (node instanceof ASTAggregateFunctionCall) {
                isAggregate[0] = true;
            }
        }
    });
    return isAggregate[0];
}
Also used : Expression(org.apache.cayenne.exp.Expression) TraversalHelper(org.apache.cayenne.exp.TraversalHelper) ASTAggregateFunctionCall(org.apache.cayenne.exp.parser.ASTAggregateFunctionCall)

Aggregations

Expression (org.apache.cayenne.exp.Expression)2 ASTAggregateFunctionCall (org.apache.cayenne.exp.parser.ASTAggregateFunctionCall)2 NodeBuilder (org.apache.cayenne.access.sqlbuilder.NodeBuilder)1 OrderingNodeBuilder (org.apache.cayenne.access.sqlbuilder.OrderingNodeBuilder)1 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)1 TraversalHelper (org.apache.cayenne.exp.TraversalHelper)1