예제 #1
0
  @SuppressWarnings("unchecked")
  @Override
  final Field<T> getFunction0(Configuration configuration) {

    // In any dialect, a single argument is always the least
    if (getArguments().length == 1) {
      return (Field<T>) getArguments()[0];
    }

    switch (configuration.family()) {
        // This implementation has O(2^n) complexity. Better implementations
        // are very welcome

      case DERBY:
        {
          Field<T> first = (Field<T>) getArguments()[0];
          Field<T> other = (Field<T>) getArguments()[1];

          if (getArguments().length > 2) {
            Field<?>[] remaining = new Field<?>[getArguments().length - 2];
            System.arraycopy(getArguments(), 2, remaining, 0, remaining.length);

            return DSL.when(first.lessThan(other), DSL.least(first, remaining))
                .otherwise(DSL.least(other, remaining));
          } else {
            return DSL.when(first.lessThan(other), first).otherwise(other);
          }
        }

      case FIREBIRD:
        return function("minvalue", getDataType(), getArguments());

      case SQLITE:
        return function("min", getDataType(), getArguments());

      default:
        return function("least", getDataType(), getArguments());
    }
  }
예제 #2
0
파일: Nvl.java 프로젝트: nablaone/jOOQ
  @Override
  final Field<T> getFunction0(Configuration configuration) {
    switch (configuration.family()) {
      case H2:
      case HSQLDB:
        return field("{nvl}({0}, {1})", getDataType(), arg1, arg2);

      case DERBY:
      case POSTGRES:
        return field("{coalesce}({0}, {1})", getDataType(), arg1, arg2);

      case MARIADB:
      case MYSQL:
      case SQLITE:
        return field("{ifnull}({0}, {1})", getDataType(), arg1, arg2);

      default:
        return DSL.when(arg1.isNotNull(), arg1).otherwise(arg2);
    }
  }