use of oracle.sql.TIMESTAMPLTZ in project symmetric-ds by JumpMind.
the class OracleBulkDatabaseWriterTest method checkTimestampLTZ.
private void checkTimestampLTZ(Object value, Connection oracleConnection, final String... expectedValues) throws SQLException {
TIMESTAMPLTZ timestamp = (TIMESTAMPLTZ) value;
String actualTimestampString = timestamp.stringValue(oracleConnection);
boolean match = false;
for (String expectedValue : expectedValues) {
if (StringUtils.equals(expectedValue, actualTimestampString)) {
match = true;
break;
}
}
Assert.assertTrue(actualTimestampString + " not found in " + Arrays.toString(expectedValues), match);
}
use of oracle.sql.TIMESTAMPLTZ 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