diff --git a/jOOQ/src/main/java/org/jooq/impl/Expression.java b/jOOQ/src/main/java/org/jooq/impl/Expression.java index be95e04bbc..f8ad508652 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Expression.java +++ b/jOOQ/src/main/java/org/jooq/impl/Expression.java @@ -117,7 +117,7 @@ final class Expression extends AbstractField { private static final Set SUPPORT_BIT_AND = SQLDialect.supportedBy(H2, HSQLDB); private static final Set SUPPORT_BIT_OR_XOR = SQLDialect.supportedBy(H2, HSQLDB); private static final Set EMULATE_BIT_XOR = SQLDialect.supportedBy(SQLITE); - private static final Set EMULATE_SHR_SHL = SQLDialect.supportedBy(H2, HSQLDB); + private static final Set EMULATE_SHR_SHL = SQLDialect.supportedBy(HSQLDB); private static final Set HASH_OP_FOR_BIT_XOR = SQLDialect.supportedBy(POSTGRES); private final Field lhs; @@ -189,27 +189,28 @@ final class Expression extends AbstractField { 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) 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) 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) 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) castIfNeeded(DSL.power(two(), rhsAsNumber()), lhs))); + } // These operators are not supported in any dialect else if (BIT_NAND == operator) diff --git a/jOOQ/src/main/java/org/jooq/impl/Neg.java b/jOOQ/src/main/java/org/jooq/impl/Neg.java index a00121ef27..eb6c49fd0f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Neg.java +++ b/jOOQ/src/main/java/org/jooq/impl/Neg.java @@ -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 extends AbstractField { * Generated UID */ private static final long serialVersionUID = 7624782102883057433L; - private static final Set EMULATE_BIT_NOT = SQLDialect.supportedBy(H2, HSQLDB); - - - - + private static final Set EMULATE_BIT_NOT = SQLDialect.supportedBy(HSQLDB); + private static final Set SUPPORT_BIT_NOT = SQLDialect.supportedBy(H2); private final ExpressionOperator operator; private final Field field; @@ -88,12 +84,10 @@ final class Neg extends AbstractField { 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)