@Override public void write(DataBuffer buff, Object obj) { Timestamp t = (Timestamp) obj; writeValue(buff, ValueTimestamp.get(t)); }
/** * Calculate the normalized timestamp. * * @param absoluteDay the absolute day * @param nanos the nanoseconds (may be negative or larger than one day) * @return the timestamp */ public static ValueTimestamp normalizeTimestamp(long absoluteDay, long nanos) { if (nanos > NANOS_PER_DAY || nanos < 0) { long d; if (nanos > NANOS_PER_DAY) { d = nanos / NANOS_PER_DAY; } else { d = (nanos - NANOS_PER_DAY + 1) / NANOS_PER_DAY; } nanos -= d * NANOS_PER_DAY; absoluteDay += d; } return ValueTimestamp.fromDateValueAndNanos(dateValueFromAbsoluteDay(absoluteDay), nanos); }
@Override public void writeValue(DataBuffer buff, Value v) { ValueTimestamp ts = (ValueTimestamp) v; long dateValue = ts.getDateValue(); long nanos = ts.getNanos(); long millis = nanos / 1000000; nanos -= millis * 1000000; buff.put((byte) TIMESTAMP).putVarLong(dateValue).putVarLong(millis).putVarLong(nanos); }
return ValueDate.fromDateValue(((ValueTimestamp) this).getDateValue()); return ValueTime.fromNanos(((ValueTimestamp) this).getNanos()); return DateTimeUtils.normalizeTimestamp(0, ((ValueTime) this).getNanos()); case DATE: return ValueTimestamp.fromDateValueAndNanos(((ValueDate) this).getDateValue(), 0); return ValueDate.parse(s.trim()); case TIMESTAMP: return ValueTimestamp.parse(s.trim()); case BYTES: return ValueBytes.getNoCopy(StringUtils.convertHexToBytes(s.trim()));
case CURRENT_TIMESTAMP: { long now = session.getTransactionStart(); ValueTimestamp vt = ValueTimestamp.get(new Timestamp(now)); if (v0 != null) { Mode mode = database.getMode(); vt = (ValueTimestamp) vt.convertScale(mode.convertOnlyToSmallerScale, v0.getInt());
String timestamp = currentValue.getString(); read(); r = ValueExpression.get(ValueTimestamp.parse(timestamp)); } else if (equalsToken("X", name)) { read();
/** * Get or create a date value for the given date. * * @param dateValue the date value * @param nanos the nanoseconds * @return the value */ public static ValueTimestamp fromDateValueAndNanos(long dateValue, long nanos) { return (ValueTimestamp) Value.cache(new ValueTimestamp(dateValue, nanos)); }
/** * Updates a column in the current or insert row. * * @param columnIndex (1,2,...) * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateTimestamp(" + columnIndex + ", x);"); } update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
cal.clear(); cal.setLenient(true); long dateValue = ts.getDateValue(); long nanos = ts.getNanos(); long millis = nanos / 1000000; nanos -= millis * 1000000;
/** * Get or create a timestamp value for the given timestamp. * * @param timestamp the timestamp * @return the value */ public static ValueTimestamp get(Timestamp timestamp) { long ms = timestamp.getTime(); long nanos = timestamp.getNanos() % 1000000; long dateValue = DateTimeUtils.dateValueFromDate(ms); nanos += DateTimeUtils.nanosFromDate(ms); return fromDateValueAndNanos(dateValue, nanos); }
/** * Updates a column in the current or insert row. * * @param columnLabel the column label * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateTimestamp(" + quote(columnLabel) + ", x);"); } update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
case Value.TIMESTAMP: { ValueTimestamp ts = (ValueTimestamp) v; writeLong(ts.getDateValue()); writeLong(ts.getNanos()); break;
/** * Convert the timestamp using the specified calendar. * * @param x the time * @param calendar the calendar * @return the timestamp */ public static ValueTimestamp convertTimestamp(Timestamp x, Calendar calendar) { if (calendar == null) { throw DbException.getInvalidValueException("calendar", null); } Calendar cal = (Calendar) calendar.clone(); cal.setTimeInMillis(x.getTime()); long dateValue = dateValueFromCalendar(cal); long nanos = nanosFromCalendar(cal); nanos += x.getNanos() % 1000000; return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos); }
/** * Sets the value of a parameter. * * @param parameterIndex the parameter index (1, 2, ...) * @param x the value * @throws SQLException if this object is closed */ @Override public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException { try { if (isDebugEnabled()) { debugCode("setTimestamp(" + parameterIndex + ", " + quoteTimestamp(x) + ");"); } Value v = x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x); setParameter(parameterIndex, v); } catch (Exception e) { throw logAndConvert(e); } }
@Override public Value convertScale(boolean onlyToSmallerScale, int targetScale) { if (targetScale >= DEFAULT_SCALE) { return this; } if (targetScale < 0) { throw DbException.getInvalidValueException("scale", targetScale); } long n = nanos; BigDecimal bd = BigDecimal.valueOf(n); bd = bd.movePointLeft(9); bd = ValueDecimal.setScale(bd, targetScale); bd = bd.movePointRight(9); long n2 = bd.longValue(); if (n2 == n) { return this; } return fromDateValueAndNanos(dateValue, n2); }
v = value == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(value); break;
@Override public Value readValue(ByteBuffer buff) { long dateValue = DataUtils.readVarLong(buff); long nanos = DataUtils.readVarLong(buff) * 1000000 + DataUtils.readVarLong(buff); return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos); }
return ValueTime.get((Time) x); } else if (x instanceof Timestamp) { return ValueTimestamp.get((Timestamp) x); } else if (x instanceof java.util.Date) { return ValueTimestamp.get(new Timestamp(((java.util.Date) x).getTime())); } else if (x instanceof java.io.Reader) { Reader r = new BufferedReader((java.io.Reader) x);
return ValueTimestamp.fromDateValueAndNanos(dateValue, nanos);
value = ValueInt.get(0).convertTo(type); } else if (dt.type == Value.TIMESTAMP) { value = ValueTimestamp.get(new Timestamp(session.getTransactionStart())); } else if (dt.type == Value.TIME) { value = ValueTime.fromNanos(0);