use of org.hibernate.query.sqm.NullPrecedence in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitSortSpecification.
@Override
public SqmSortSpecification visitSortSpecification(HqlParser.SortSpecificationContext ctx) {
final SqmExpression<?> sortExpression = visitSortExpression((HqlParser.SortExpressionContext) ctx.getChild(0));
if (sortExpression == null) {
throw new ParsingException("Could not resolve sort-expression : " + ctx.getChild(0).getText());
}
if (sortExpression instanceof SqmLiteral || sortExpression instanceof SqmParameter) {
HqlLogging.QUERY_LOGGER.debugf("Questionable sorting by constant value : %s", sortExpression);
}
final SortOrder sortOrder;
final NullPrecedence nullPrecedence;
int nextIndex = 1;
if (nextIndex < ctx.getChildCount()) {
ParseTree parseTree = ctx.getChild(nextIndex);
if (parseTree instanceof HqlParser.SortDirectionContext) {
switch(((TerminalNode) parseTree.getChild(0)).getSymbol().getType()) {
case HqlParser.ASC:
sortOrder = SortOrder.ASCENDING;
break;
case HqlParser.DESC:
sortOrder = SortOrder.DESCENDING;
break;
default:
throw new SemanticException("Unrecognized sort ordering: " + parseTree.getText());
}
nextIndex++;
} else {
sortOrder = null;
}
parseTree = ctx.getChild(nextIndex);
if (parseTree instanceof HqlParser.NullsPrecedenceContext) {
switch(((TerminalNode) parseTree.getChild(1)).getSymbol().getType()) {
case HqlParser.FIRST:
nullPrecedence = NullPrecedence.FIRST;
break;
case HqlParser.LAST:
nullPrecedence = NullPrecedence.LAST;
break;
default:
throw new SemanticException("Unrecognized null precedence: " + parseTree.getText());
}
} else {
nullPrecedence = null;
}
} else {
sortOrder = null;
nullPrecedence = null;
}
return new SqmSortSpecification(sortExpression, sortOrder, nullPrecedence);
}
use of org.hibernate.query.sqm.NullPrecedence in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitSortSpecification.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ORDER BY clause
@Override
public void visitSortSpecification(SortSpecification sortSpecification) {
final Expression sortExpression = sortSpecification.getSortExpression();
final NullPrecedence nullPrecedence = sortSpecification.getNullPrecedence();
final SortOrder sortOrder = sortSpecification.getSortOrder();
final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple(sortExpression);
if (sqlTuple != null) {
String separator = NO_SEPARATOR;
for (Expression expression : sqlTuple.getExpressions()) {
appendSql(separator);
visitSortSpecification(expression, sortOrder, nullPrecedence);
separator = COMA_SEPARATOR;
}
} else {
visitSortSpecification(sortExpression, sortOrder, nullPrecedence);
}
}
Aggregations