Search in sources :

Example 1 with Datum

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);
    }
}
Also used : TimeZone(java.util.TimeZone) Datum(oracle.sql.Datum) Calendar(java.util.Calendar) Connection(java.sql.Connection) TIMESTAMPLTZ(oracle.sql.TIMESTAMPLTZ) JdbcSqlTransaction(org.jumpmind.db.sql.JdbcSqlTransaction) TIMESTAMPTZ(oracle.sql.TIMESTAMPTZ) Timestamp(java.sql.Timestamp) AbstractDatabasePlatform(org.jumpmind.db.platform.AbstractDatabasePlatform) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) BulkSqlException(org.jumpmind.db.sql.BulkSqlException)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 TimeZone (java.util.TimeZone)1 Datum (oracle.sql.Datum)1 TIMESTAMPLTZ (oracle.sql.TIMESTAMPLTZ)1 TIMESTAMPTZ (oracle.sql.TIMESTAMPTZ)1 AbstractDatabasePlatform (org.jumpmind.db.platform.AbstractDatabasePlatform)1 BulkSqlException (org.jumpmind.db.sql.BulkSqlException)1 JdbcSqlTransaction (org.jumpmind.db.sql.JdbcSqlTransaction)1