@Override public String renderOrderByElement(String expression, String collation, String order, NullPrecedence nulls) { final StringBuilder orderByElement = new StringBuilder(); if ( nulls != NullPrecedence.NONE ) { // Workaround for NULLS FIRST / LAST support. orderByElement.append( "case when " ).append( expression ).append( " is null then " ); if ( nulls == NullPrecedence.FIRST ) { orderByElement.append( "0 else 1" ); } else { orderByElement.append( "1 else 0" ); } orderByElement.append( " end, " ); } // Nulls precedence has already been handled so passing NONE value. orderByElement.append( super.renderOrderByElement( expression, collation, order, NullPrecedence.NONE ) ); return orderByElement.toString(); }
/** * Renders an ordering fragment * * @param expression The SQL order expression. In case of {@code @OrderBy} annotation user receives property placeholder * (e.g. attribute name enclosed in '{' and '}' signs). * @param collation Collation string in format {@code collate IDENTIFIER}, or {@code null} * if expression has not been explicitly specified. * @param order Order direction. Possible values: {@code asc}, {@code desc}, or {@code null} * if expression has not been explicitly specified. * @param nulls Nulls precedence. Default value: {@link NullPrecedence#NONE}. * @return Renders single element of {@code ORDER BY} clause. */ public String renderOrderByElement(String expression, String collation, String order, NullPrecedence nulls) { final StringBuilder orderByElement = new StringBuilder( expression ); if ( collation != null ) { orderByElement.append( " " ).append( collation ); } if ( order != null ) { orderByElement.append( " " ).append( order ); } if ( nulls != NullPrecedence.NONE ) { orderByElement.append( " nulls " ).append( nulls.name().toLowerCase() ); } return orderByElement.toString(); }
@Override protected String renderOrderByElement(String expression, String order, String nulls) { final NullPrecedence nullPrecedence = NullPrecedence.parse( nulls, sessionFactory.getSettings() .getDefaultNullPrecedence() ); return sessionFactory.getDialect().renderOrderByElement( expression, null, order, nullPrecedence ); }
public NullPrecedence getDefaultNullPrecedence() { return defaultNullPrecedence; }
void setDefaultNullPrecedence(NullPrecedence defaultNullPrecedence) { this.defaultNullPrecedence = defaultNullPrecedence; }
@Override protected String renderOrderByElement(String expression, String collation, String order, String nulls) { final NullPrecedence nullPrecedence = NullPrecedence.parse( nulls, sessionFactory.getSettings().getDefaultNullPrecedence() ); return sessionFactory.getDialect().renderOrderByElement( expression, collation, order, nullPrecedence ); }
@Override public String renderOrderByElement(final String expression, final String collation, final String order, final NullPrecedence nulls) { return this.wrapped.renderOrderByElement(expression, collation, order, nulls); }
/** * Defines precedence for nulls. * * @param nullPrecedence The null precedence to use * * @return {@code this}, for method chaining */ public Order nulls(NullPrecedence nullPrecedence) { this.nullPrecedence = nullPrecedence; return this; }