@Override public java.sql.Timestamp toTimestamp(OptimizedElementArray row, int columnPosition, Calendar cal) throws SQLException { long ts = row.getLong(columnPosition - 1); if (cal == null) { return Converters.getTimestamp(ts); } else { // pass only the seconds for epoch time long seconds = ts / NANOS_PER_SECOND; long nanos = ts % NANOS_PER_SECOND; if (nanos < 0) { nanos += NANOS_PER_SECOND; seconds--; } cal.setTimeInMillis(seconds * 1000L); return Converters.getTimestamp(cal.getTimeInMillis() * NANOS_PER_MILLI + nanos); } } @Override
public final Timestamp getTimestamp(int index) { return Converters.getTimestamp(getLong(index)); }
@Override public final java.sql.Timestamp toTimestamp(OptimizedElementArray row, int columnPosition, Calendar cal) throws SQLException { String str = toString(row, columnPosition); if (str != null) { java.sql.Timestamp ts; try { ts = java.sql.Timestamp.valueOf(str); } catch (IllegalArgumentException iae) { throw ThriftExceptionUtil.newSQLException( SQLState.LANG_DATE_SYNTAX_EXCEPTION, iae, str); } if (cal == null) { return ts; } else { cal.setTime(ts); return Converters.getTimestamp(cal.getTimeInMillis() * NANOS_PER_MILLI + ts.getNanos()); } } else { throw ThriftExceptionUtil.newSQLException( SQLState.LANG_DATE_SYNTAX_EXCEPTION, null, "<NULL>"); } } @Override
@Override public java.sql.Timestamp toTimestamp(OptimizedElementArray row, int columnPosition, Calendar cal) throws SQLException { Object o = toObject(row, columnPosition); if (o instanceof java.sql.Timestamp) { return (java.sql.Timestamp)o; } else if (o instanceof Number) { return Converters.getTimestamp(((Number)o).longValue()); } else { throw newTypeConversionException( getType().toString(), "Timestamp", columnPosition); } } @Override