[jOOQ/jOOQ#9588][jOOQ/jOOQ#9589] Use H2 BITNOT(), LSHIFT(), and RSHIFT()
No need to emulate `bitNot()`, `shr()`, and `shl()` anymore in H2 1.4.200.
This commit is contained in:
parent
8d01407974
commit
66670b5470
@ -117,7 +117,7 @@ final class Expression<T> extends AbstractField<T> {
|
||||
private static final Set<SQLDialect> SUPPORT_BIT_AND = SQLDialect.supportedBy(H2, HSQLDB);
|
||||
private static final Set<SQLDialect> SUPPORT_BIT_OR_XOR = SQLDialect.supportedBy(H2, HSQLDB);
|
||||
private static final Set<SQLDialect> EMULATE_BIT_XOR = SQLDialect.supportedBy(SQLITE);
|
||||
private static final Set<SQLDialect> EMULATE_SHR_SHL = SQLDialect.supportedBy(H2, HSQLDB);
|
||||
private static final Set<SQLDialect> EMULATE_SHR_SHL = SQLDialect.supportedBy(HSQLDB);
|
||||
private static final Set<SQLDialect> HASH_OP_FOR_BIT_XOR = SQLDialect.supportedBy(POSTGRES);
|
||||
|
||||
private final Field<T> lhs;
|
||||
@ -189,27 +189,28 @@ final class Expression<T> extends AbstractField<T> {
|
||||
DSL.bitNot(DSL.bitAnd(lhsAsNumber(), rhsAsNumber())),
|
||||
DSL.bitOr(lhsAsNumber(), rhsAsNumber())));
|
||||
|
||||
else if (operator == SHL || operator == SHR) {
|
||||
if (family == H2)
|
||||
ctx.visit(DSL.function(SHL == operator ? "lshift" : "rshift", getDataType(), arguments));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Some dialects support shifts as functions
|
||||
else if (FIREBIRD == family)
|
||||
ctx.visit(function(SHL == operator ? "bin_shl" : "bin_shr", getDataType(), arguments));
|
||||
|
||||
// Many dialects don't support shifts. Use multiplication/division instead
|
||||
else if (SHL == operator && EMULATE_SHR_SHL.contains(family))
|
||||
ctx.visit(lhs.mul((Field<? extends Number>) castIfNeeded(DSL.power(two(), rhsAsNumber()), lhs)));
|
||||
// Many dialects don't support shifts. Use multiplication/division instead
|
||||
else if (SHL == operator && EMULATE_SHR_SHL.contains(family))
|
||||
ctx.visit(lhs.mul((Field<? extends Number>) castIfNeeded(DSL.power(two(), rhsAsNumber()), lhs)));
|
||||
|
||||
// [#3962] This emulation is expensive. If this is emulated, BitCount should
|
||||
// use division instead of SHR directly
|
||||
else if (SHR == operator && EMULATE_SHR_SHL.contains(family))
|
||||
ctx.visit(lhs.div((Field<? extends Number>) castIfNeeded(DSL.power(two(), rhsAsNumber()), lhs)));
|
||||
|
||||
// Some dialects support shifts as functions
|
||||
else if (SHL == operator && FIREBIRD == family)
|
||||
ctx.visit(function("bin_shl", getDataType(), arguments));
|
||||
else if (SHR == operator && FIREBIRD == family)
|
||||
ctx.visit(function("bin_shr", getDataType(), arguments));
|
||||
// [#3962] This emulation is expensive. If this is emulated, BitCount should
|
||||
// use division instead of SHR directly
|
||||
else if (SHR == operator && EMULATE_SHR_SHL.contains(family))
|
||||
ctx.visit(lhs.div((Field<? extends Number>) castIfNeeded(DSL.power(two(), rhsAsNumber()), lhs)));
|
||||
}
|
||||
|
||||
// These operators are not supported in any dialect
|
||||
else if (BIT_NAND == operator)
|
||||
|
||||
@ -51,7 +51,6 @@ import java.util.Set;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
// ...
|
||||
import org.jooq.SQLDialect;
|
||||
|
||||
/**
|
||||
@ -64,11 +63,8 @@ final class Neg<T> extends AbstractField<T> {
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 7624782102883057433L;
|
||||
private static final Set<SQLDialect> EMULATE_BIT_NOT = SQLDialect.supportedBy(H2, HSQLDB);
|
||||
|
||||
|
||||
|
||||
|
||||
private static final Set<SQLDialect> EMULATE_BIT_NOT = SQLDialect.supportedBy(HSQLDB);
|
||||
private static final Set<SQLDialect> SUPPORT_BIT_NOT = SQLDialect.supportedBy(H2);
|
||||
|
||||
private final ExpressionOperator operator;
|
||||
private final Field<T> field;
|
||||
@ -88,12 +84,10 @@ final class Neg<T> extends AbstractField<T> {
|
||||
ctx.sql("(0 - ")
|
||||
.visit(field)
|
||||
.sql(" - 1)");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else if (operator == BIT_NOT && SUPPORT_BIT_NOT.contains(family))
|
||||
ctx.sql("bitnot(")
|
||||
.visit(field)
|
||||
.sql(')');
|
||||
else if (operator == BIT_NOT && family == FIREBIRD)
|
||||
ctx.sql("bin_not(")
|
||||
.visit(field)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user