Search in sources :

Example 1 with OrderingExpression

use of io.requery.query.OrderingExpression in project requery by requery.

the class OrderByGenerator method write.

@Override
public void write(Output output, OrderByElement query) {
    Set<Expression<?>> orderBy = query.getOrderByExpressions();
    if (orderBy != null && orderBy.size() > 0) {
        QueryBuilder qb = output.builder();
        qb.keyword(ORDER, BY);
        int i = 0;
        int size = orderBy.size();
        for (Expression<?> order : orderBy) {
            if (order.getExpressionType() == ExpressionType.ORDERING) {
                OrderingExpression ordering = (OrderingExpression) order;
                output.appendColumn(ordering.getInnerExpression());
                qb.keyword(ordering.getOrder() == Order.ASC ? ASC : DESC);
                if (ordering.getNullOrder() != null) {
                    qb.keyword(NULLS);
                    switch(ordering.getNullOrder()) {
                        case FIRST:
                            qb.keyword(FIRST);
                            break;
                        case LAST:
                            qb.keyword(LAST);
                            break;
                    }
                }
            } else {
                output.appendColumn(order);
            }
            if (i < size - 1) {
                qb.append(",");
            }
            i++;
        }
    }
}
Also used : OrderingExpression(io.requery.query.OrderingExpression) Expression(io.requery.query.Expression) OrderingExpression(io.requery.query.OrderingExpression) QueryBuilder(io.requery.sql.QueryBuilder)

Aggregations

Expression (io.requery.query.Expression)1 OrderingExpression (io.requery.query.OrderingExpression)1 QueryBuilder (io.requery.sql.QueryBuilder)1