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++;
}
}
}
Aggregations