in src/main/java/com/aliyun/odps/jdbc/utils/transformer/to/jdbc/ToJdbcTimeTransfomer.java [45:92]
public Object transform(
Object o,
String charset,
Calendar cal,
TimeZone timeZone) throws SQLException {
if (o == null) {
return null;
}
try {
if (o instanceof ZonedDateTime) {
if (timeZone != null) {
o = ((ZonedDateTime) o).withZoneSameInstant(timeZone.toZoneId());
}
return java.sql.Time.valueOf(((ZonedDateTime) o).toLocalTime());
} else if (o instanceof Instant) {
ZonedDateTime
zonedDateTime =
ZonedDateTime.ofInstant((Instant) o,
timeZone == null ? ZoneId.systemDefault()
: timeZone.toZoneId());
return java.sql.Time.valueOf(zonedDateTime.toLocalTime());
} else if (o instanceof LocalDateTime) {
return ((LocalDateTime) o).toLocalTime();
} else if (o instanceof byte[]) {
o = encodeBytes((byte[]) o, charset);
try {
SimpleDateFormat timeFormat = TIME_FORMAT.get();
if (cal != null) {
timeFormat.setCalendar(cal);
}
return new java.sql.Time(timeFormat.parse((String) o).getTime());
} finally {
restoreToDefaultCalendar();
}
} 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.Time.class, e.getMessage());
throw new SQLException(errorMsg, e);
}
}