/** * Converts a java.util.Date into a org.tentackle.misc.Timestamp. * * @param date the date * @return the timestamp, null if date was null */ public static Timestamp toTimestamp(java.util.Date date) { return date == null ? null : new Timestamp(date.getTime()); }
/** * Sets the UTC flag null-safe.<br> * Method provided to reduce generated code. * * @param timestamp the timestamp, may be null * @param utc the UTC flag */ public static void setUTC(Timestamp timestamp, boolean utc) { if (timestamp != null) { timestamp.setUTC(utc); } }
@Override public void setNanos(int n) { assertNotFrozen(); super.setNanos(n); }
/** * Creates a frozen timestamp. * * @param epoch epochal milliseconds since January 1, 1970, 00:00:00 GMT * @param nanos the new fractional seconds component * @return the frozen timestamp */ public static Timestamp createFrozen(long epoch, int nanos) { Timestamp timestamp = new Timestamp(epoch); timestamp.setNanos(nanos); timestamp.freeze(); return timestamp; }
Class<?> type = getComponent().getType(); if (org.tentackle.common.Timestamp.class.isAssignableFrom(type)) { org.tentackle.common.Timestamp ts = new org.tentackle.common.Timestamp(date.getTime()); if (getComponent().isUTC()) { ts.setUTC(true);
/** * Save the state of this object to a stream. * * @serialData the value YYYYMMDDHHMMSS is emitted. This allows serializing * and deserializing in different timezones without changing the timestamp. * * @param s the stream * @throws IOException if writing to stream failed */ private void writeObject(ObjectOutputStream s) throws IOException { s.writeBoolean(utc); if (utc) { s.writeShort(getCalendar().get(Calendar.YEAR)); s.writeByte(getCalendar().get(Calendar.MONTH)); s.writeByte(getCalendar().get(Calendar.DAY_OF_MONTH)); s.writeByte(getCalendar().get(Calendar.HOUR_OF_DAY)); s.writeByte(getCalendar().get(Calendar.MINUTE)); s.writeByte(getCalendar().get(Calendar.SECOND)); s.writeInt(getNanos()); } else { s.writeLong(getTime()); s.writeInt(getNanos()); } s.writeBoolean(frozen); }
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>java.sql.Timestamp</code> in the Java programming language. * * @param pos the parameter index in the result set * @param timezone the calendar providing the timezone configuration * @param mapNull true if 1.1.1970 00:00:00.000 should be mapped to null * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> */ public Timestamp getTimestamp(int pos, Calendar timezone, boolean mapNull) { try { java.sql.Timestamp ts = timezone == null ? resources.rs.getTimestamp(pos + columnOffset) : resources.rs.getTimestamp(pos + columnOffset, timezone); if (ts == null || (mapNull && ts.equals(DateHelper.MIN_TIMESTAMP))) { // mindate is translated back to null return null; } return Timestamp.createFrozen(ts.getTime(), ts.getNanos()); } catch (SQLException e) { throw new PersistenceException(resources.db, e); } }
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>java.sql.Timestamp</code> in the Java programming language. * * @param name the label for the column specified with the SQL AS clause. * If the SQL AS clause was not specified, then the label is the name of the column * @param timezone the calendar providing the timezone configuration * @param mapNull true if 1.1.1970 00:00:00.000 should be mapped to null * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> */ public Timestamp getTimestamp(String name, Calendar timezone, boolean mapNull) { try { java.sql.Timestamp ts = timezone == null ? resources.rs.getTimestamp(name) : resources.rs.getTimestamp(name, timezone); if (ts == null || (mapNull && ts.equals(DateHelper.MIN_TIMESTAMP))) { // mintimestamp is translated back to null return null; } return Timestamp.createFrozen(ts.getTime(), ts.getNanos()); } catch (SQLException e) { throw new PersistenceException(resources.db, e); } }
/** * Gets the current system time plus an optional offset. * * @param offsetMillis the offset to the current system time in milliseconds * @return current Timestamp */ public static Timestamp now(long offsetMillis) { return new Timestamp(System.currentTimeMillis() + offsetMillis); }
/** * Sets the attribute when. * * @param when time of event */ public void setWhen(Timestamp when) { assertMutable(); this.when = when; Timestamp.setUTC(when, false); Freezable.freeze(when); }
@Deprecated @Override public void setSeconds(int seconds) { assertNotFrozen(); super.setSeconds(seconds); }
/** * Retrieves the value of the designated column in the current row * of this <code>ResultSet</code> object as * a <code>java.sql.Timestamp</code> in the Java programming language. * * @param timezone the calendar providing the timezone configuration * @param mapNull true if 1.1.1970 00:00:00.000 should be mapped to null * @return the column value; if the value is SQL <code>NULL</code>, the * value returned is <code>null</code> */ public Timestamp getTimestamp(Calendar timezone, boolean mapNull) { try { int pos = nextConfiguredIndex(); java.sql.Timestamp ts = timezone == null ? resources.rs.getTimestamp(pos + columnOffset) : resources.rs.getTimestamp(pos + columnOffset, timezone); if (ts == null || (mapNull && ts.equals(DateHelper.MIN_TIMESTAMP))) { // mindate is translated back to null return null; } return Timestamp.createFrozen(ts.getTime(), ts.getNanos()); } catch (SQLException e) { throw new PersistenceException(resources.db, e); } }
/** * Converts a Calendar into a org.tentackle.misc.Timestamp. * * @param cal the calendar * @return the timestamp, null if cal was null */ public static Timestamp toTimestamp(Calendar cal) { return cal == null ? null : new Timestamp(cal.getTime().getTime()); }
/** * Sets the attribute processed. * * @param processed processing time */ public void setProcessed(Timestamp processed) { assertMutable(); this.processed = processed; Timestamp.setUTC(processed, false); Freezable.freeze(processed); }
@Deprecated @Override public void setMonth(int month) { assertNotFrozen(); super.setMonth(month); }
/** * Marks a pooled db unused. */ public void unUse(Db db) { // switch back to hard reference this.db = refDb.get(); if (this.db == null) { throw new PersistenceException("unexpected loss of reference to " + dbStr + " (last use by " + usingThreadStr + " since " + new Timestamp(usedSince) + ")"); } if (this.db != db) { this.db = null; throw new PersistenceException("attempt to unuse " + db + " in wrong slot " + dbStr + " (last use by " + usingThreadStr + " since " + new Timestamp(usedSince) + ")"); } unusedSince = System.currentTimeMillis(); usedSince = 0; usingThreadStr = null; mdcStr = null; }
@Override public Object getViewValue() { /** * Notice: we still test for java.sql.xxxx types to allow apps * to use either java.sql.xx or org.tentackle.misc.xx. */ try { Class<?> type = getMember().getType(); if (java.sql.Timestamp.class.isAssignableFrom(type)) { Timestamp timestamp = ((SqlDateField) getComponent()).getTimestamp(); if (timestamp != null && utc) { timestamp.setUTC(true); } return timestamp; } else if (java.sql.Time.class.isAssignableFrom(type)) { return ((SqlDateField) getComponent()).getTime(); } else if (java.sql.Date.class.isAssignableFrom(type)) { return ((SqlDateField) getComponent()).getDate(); } else { // else: java.util.Date return super.getViewValue(); } } catch (Exception ex) { throw new BindingException("could not get component value for " + getMember(), ex); } }
/** * {@inheritDoc} * <p> * Overridden to clear the lazy calendar and to check for frozen. */ @Override public void setTime(long timestamp) { assertNotFrozen(); super.setTime(timestamp); cal = null; }
/** * Gets the SQL-Timestamp. * * @return the org.tentackle.misc.Timestamp, null if field is empty */ @Override public org.tentackle.common.Timestamp getTimestamp() { Date date = getFormValue(); return date == null ? null : new org.tentackle.common.Timestamp(date.getTime()); }
@Deprecated @Override public void setHours(int hours) { assertNotFrozen(); super.setHours(hours); }