public Object transform()

in src/main/java/com/aliyun/odps/jdbc/utils/transformer/to/jdbc/ToJdbcTimestampTransformer.java [63:109]


  public Object transform(
      Object o,
      String charset,
      Calendar cal,
      TimeZone timeZone,
      TypeInfo typeInfo) throws SQLException {
    if (o == null) {
      return null;
    }
    // if typeInfo is null or not time type, use default (TIMESTAMP)
    if (typeInfo == null || (typeInfo.getOdpsType() != OdpsType.DATETIME
                             && typeInfo.getOdpsType() != OdpsType.TIMESTAMP
                             && typeInfo.getOdpsType() != OdpsType.TIMESTAMP_NTZ)) {
      typeInfo = TypeInfoFactory.TIMESTAMP;
    }
    try {
      if (o instanceof byte[]) {
        String str = encodeBytes((byte[]) o, charset);
        // convert to local date
        o = RecordConverterCache.get(timeZone).parseObject(str, typeInfo);
      }
      if (o instanceof Binary) {
        String str = encodeBytes(((Binary) o).data(), charset);
        // convert to local date
        o = RecordConverterCache.get(timeZone).parseObject(str, typeInfo);
      }

      if (o instanceof ZonedDateTime) {
        return TimeUtils.getTimestamp(((ZonedDateTime) o).toInstant(), timeZone);
      } else if (o instanceof Instant) {
        return TimeUtils.getTimestamp((Instant) o, timeZone);
      } else if (o instanceof LocalDateTime) {
        // LocalDatetime is not time zone aware, so we always convert it to UTC
        return TimeUtils.getTimestamp((LocalDateTime) o, TimeUtils.UTC);
      } else {
        String errorMsg = getInvalidTransformationErrorMsg(o.getClass(), java.sql.Timestamp.class);
        throw new SQLException(errorMsg);
      }
    } catch (SQLException e) {
      throw e;
    } catch (Exception e) {
      String
          errorMsg =
          getTransformationErrMsg(Objects.toString(o), java.sql.Timestamp.class, e.getMessage());
      throw new SQLException(errorMsg, e);
    }
  }