use of oracle.sql.Datum in project symmetric-ds by JumpMind.
the class OracleBulkDatabaseWriter method parseTimestampTZ.
protected Datum parseTimestampTZ(int type, String value) {
if (value == null || StringUtils.isEmpty(value.trim())) {
return null;
}
try {
Timestamp timestamp = null;
TimeZone timezone = null;
try {
// Try something like: 2015-11-20 13:37:44.000000000
timestamp = Timestamp.valueOf(value.trim());
timezone = TimeZone.getDefault();
} catch (Exception ex) {
log.debug("Failed to convert value to timestamp.", ex);
// Now expecting something like: 2015-11-20 13:37:44.000000000 +08:00
int split = value.lastIndexOf(" ");
String timestampString = value.substring(0, split).trim();
if (timestampString.endsWith(".")) {
// Cover case where triggers would export format like "2007-01-02 03:20:10."
timestampString = timestampString.substring(0, timestampString.length() - 1);
}
String timezoneString = value.substring(split).trim();
timestamp = Timestamp.valueOf(timestampString);
timezone = ((AbstractDatabasePlatform) platform).getTimeZone(timezoneString);
// the timestamp component needs to actually be in UTC.
if (type == OracleTypes.TIMESTAMPTZ) {
timestamp = toUTC(timestamp, timezone);
}
}
Calendar timezoneCalender = Calendar.getInstance();
timezoneCalender.setTimeZone(timezone);
timezoneCalender.setTime(timestamp);
JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction;
Connection c = jdbcTransaction.getConnection();
Connection oracleConnection = jdbcExtractor.getNativeConnection(c);
Datum ts = null;
if (type == OracleTypes.TIMESTAMPTZ) {
ts = new TIMESTAMPTZ(oracleConnection, timestamp, timezoneCalender);
} else {
ts = new TIMESTAMPLTZ(oracleConnection, timestamp);
}
return ts;
} catch (Exception ex) {
log.info("Failed to convert '" + value + "' to TIMESTAMPTZ.");
throw platform.getSqlTemplate().translate(ex);
}
}
Aggregations