Ejemplo n.º 1
0
  @Override
  final Field<BigDecimal> getFunction0(Configuration configuration) {
    switch (configuration.dialect().family()) {
      case ASE:
      case CUBRID:
      case HSQLDB:
      case INGRES:
      case MARIADB:
      case MYSQL:
      case POSTGRES:
      case SQLSERVER:
      case SYBASE:
        return DSL.exp(argument.mul(two())).sub(one()).div(DSL.exp(argument.mul(two())).add(one()));

      default:
        return function("tanh", SQLDataType.NUMERIC, argument);
    }
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Override
  final Field<T> getFunction0(Configuration configuration) {
    SQLDialect dialect = configuration.getDialect();

    // ---------------------------------------------------------------------
    // XXX: Bitwise operators
    // ---------------------------------------------------------------------

    // DB2, H2 and HSQLDB know functions, instead of operators
    if (BIT_AND == operator && asList(DB2, H2, HSQLDB, ORACLE).contains(dialect)) {
      return function("bitand", getDataType(), getArguments());
    } else if (BIT_AND == operator && FIREBIRD == dialect) {
      return function("bin_and", getDataType(), getArguments());
    } else if (BIT_XOR == operator && asList(DB2, H2, HSQLDB).contains(dialect)) {
      return function("bitxor", getDataType(), getArguments());
    } else if (BIT_XOR == operator && FIREBIRD == dialect) {
      return function("bin_xor", getDataType(), getArguments());
    } else if (BIT_OR == operator && asList(DB2, H2, HSQLDB).contains(dialect)) {
      return function("bitor", getDataType(), getArguments());
    } else if (BIT_OR == operator && FIREBIRD == dialect) {
      return function("bin_or", getDataType(), getArguments());
    }

    // Oracle has to simulate or/xor
    else if (BIT_OR == operator && ORACLE == dialect) {
      return lhs.sub(bitAnd(lhsAsNumber(), rhsAsNumber())).add(rhsAsNumber());
    }

    // ~(a & b) & (a | b)
    else if (BIT_XOR == operator && asList(ORACLE, SQLITE).contains(dialect)) {
      return (Field<T>)
          bitAnd(bitNot(bitAnd(lhsAsNumber(), rhsAsNumber())), bitOr(lhsAsNumber(), rhsAsNumber()));
    }

    // Many dialects don't support shifts. Use multiplication/division instead
    else if (SHL == operator
        && asList(ASE, DB2, H2, HSQLDB, INGRES, ORACLE, SQLSERVER, SYBASE).contains(dialect)) {
      return lhs.mul(Factory.power(two(), rhsAsNumber()));
    } else if (SHR == operator
        && asList(ASE, DB2, H2, HSQLDB, INGRES, ORACLE, SQLSERVER, SYBASE).contains(dialect)) {
      return lhs.div(Factory.power(two(), rhsAsNumber()));
    }

    // Some dialects support shifts as functions
    else if (SHL == operator && FIREBIRD == dialect) {
      return function("bin_shl", getDataType(), getArguments());
    } else if (SHR == operator && FIREBIRD == dialect) {
      return function("bin_shr", getDataType(), getArguments());
    }

    // These operators are not supported in any dialect
    else if (BIT_NAND == operator) {
      return (Field<T>) bitNot(bitAnd(lhsAsNumber(), rhsAsNumber()));
    } else if (BIT_NOR == operator) {
      return (Field<T>) bitNot(bitOr(lhsAsNumber(), rhsAsNumber()));
    } else if (BIT_XNOR == operator) {
      return (Field<T>) bitNot(bitXor(lhsAsNumber(), rhsAsNumber()));
    }

    // ---------------------------------------------------------------------
    // XXX: Date time arithmetic operators
    // ---------------------------------------------------------------------

    // [#585] Date time arithmetic for numeric or interval RHS
    else if (asList(ADD, SUBTRACT).contains(operator)
        && lhs.getDataType().isDateTime()
        && (rhs.get(0).getDataType().isNumeric() || rhs.get(0).getDataType().isInterval())) {

      return new DateExpression();
    }

    // ---------------------------------------------------------------------
    // XXX: Other operators
    // ---------------------------------------------------------------------

    // Use the default operator expression for all other cases
    else {
      return new DefaultExpression();
    }
  }