@Override public void setTimestamp(Timestamp val, Calendar cal) throws SQLException { field = new Field(null, "string"); if (val == null) { jsonObject = null; isNull = true; } else { if (cal != null) { cal = (Calendar) cal.clone(); } jsonObject = timestampUtils.toString(cal, val); } }
@Override public Timestamp getTimestamp(Calendar cal) throws SQLException { Timestamp ts; if (jsonObject == null) { isNull = true; return null; } try { if (jsonObject instanceof java.util.Date || jsonObject instanceof java.sql.Date) { ts = new Timestamp(((java.util.Date) jsonObject).getTime()); } else if (jsonObject instanceof String) { ts = timestampUtils.parseTimestamp((String) jsonObject); } else { throw new SQLException("value " + jsonObject + " is not a Timestamp"); } } catch (Exception ex) { throw new SQLException("value " + jsonObject + "is not a Timestamp", ex); } if (cal != null) { ts = timestampUtils.applyCalendar(cal, ts); } /* // check to see if there is a calendar and that it is different than the one used to parse */ return ts; }
@Override public Date getDate(Calendar cal) throws SQLException { Date date = null; if (jsonObject == null) { isNull = true; return null; } try { if (jsonObject instanceof String) { date = timestampUtils.parse((String) jsonObject); } if (jsonObject instanceof Date) { date = (Date) jsonObject; } if (jsonObject instanceof java.util.Date) { date = new Date(((java.util.Date) jsonObject).getTime()); } } catch (Exception ex) { throw new SQLException("value " + jsonObject + " is not a date"); } if (cal != null) { date = timestampUtils.applyCalendar(cal, date); } return date; }
@Override public Time getTime(Calendar cal) throws SQLException { Time time; if (jsonObject == null) return null; try { time = timestampUtils.parseTime((String) jsonObject); } catch (Exception ex) { throw new SQLException("value " + jsonObject + " is not a Time", ex); } if (cal != null) { time = timestampUtils.applyCalendar(cal, time); } return time; }