Emulate null ordering for CockroachDB
This commit is contained in:
parent
127ee26f82
commit
c096b463ee
|
@ -14,6 +14,7 @@ import java.util.Map;
|
|||
import org.hibernate.JDBCException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.NullPrecedence;
|
||||
import org.hibernate.PessimisticLockException;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -234,6 +235,25 @@ public class CockroachDB192Dialect extends Dialect {
|
|||
return true;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForUpdateString(String aliases) {
|
||||
return getForUpdateString() + " of " + aliases;
|
||||
|
|
Loading…
Reference in New Issue