FileDocCategorySizeDatePackage
TimestampType.javaAPI DocHibernate 3.2.53546Tue Dec 20 22:13:30 GMT 2005org.hibernate.type

TimestampType

public class TimestampType extends MutableType implements LiteralType, VersionType
timestamp: A type that maps an SQL TIMESTAMP to a Java java.util.Date or java.sql.Timestamp.
author
Gavin King

Fields Summary
private static final String
TIMESTAMP_FORMAT
Constructors Summary
Methods Summary
public java.lang.ObjectdeepCopyNotNull(java.lang.Object value)

		if ( value instanceof Timestamp ) {
			Timestamp orig = (Timestamp) value;
			Timestamp ts = new Timestamp( orig.getTime() );
			ts.setNanos( orig.getNanos() );
			return ts;
		}
		else {
			java.util.Date orig = (java.util.Date) value;
			return new java.util.Date( orig.getTime() );
		}
	
public java.lang.ObjectfromStringValue(java.lang.String xml)

		try {
			return new Timestamp( new SimpleDateFormat(TIMESTAMP_FORMAT).parse(xml).getTime() );
		}
		catch (ParseException pe) {
			throw new HibernateException("could not parse XML", pe);
		}
	
public java.lang.Objectget(java.sql.ResultSet rs, java.lang.String name)


	        
		return rs.getTimestamp(name);
	
public java.util.ComparatorgetComparator()

		return ComparableComparator.INSTANCE;
	
public intgetHashCode(java.lang.Object x, org.hibernate.EntityMode entityMode)

		java.util.Date ts = (java.util.Date) x;
		return new Long( ts.getTime() / 1000 ).hashCode();
	
public java.lang.StringgetName()

 return "timestamp"; 
public java.lang.ClassgetReturnedClass()

		return java.util.Date.class;
	
public booleanisEqual(java.lang.Object x, java.lang.Object y)


		if (x==y) return true;
		if (x==null || y==null) return false;

		long xTime = ( (java.util.Date) x ).getTime();
		long yTime = ( (java.util.Date) y ).getTime();
		boolean xts = x instanceof Timestamp;
		boolean yts = y instanceof Timestamp;
		int xNanos = xts ? ( (Timestamp) x ).getNanos() : 0;
		int yNanos = yts ? ( (Timestamp) y ).getNanos() : 0;
		if ( !Environment.jvmHasJDK14Timestamp() ) {
			xTime += xNanos / 1000000;
			yTime += yNanos / 1000000;
		}
		if ( xTime!=yTime ) return false;
		if (xts && yts) {
			// both are Timestamps
			int xn = xNanos % 1000000;
			int yn = yNanos % 1000000;
			return xn==yn;
		}
		else {
			// at least one is a plain old Date
			return true;
		}

	
public java.lang.Objectnext(java.lang.Object current, org.hibernate.engine.SessionImplementor session)

		return seed( session );
	
public java.lang.StringobjectToSQLString(java.lang.Object value, org.hibernate.dialect.Dialect dialect)

		return '\'" + new Timestamp( ( (java.util.Date) value ).getTime() ).toString() + '\'";
	
public java.lang.Objectseed(org.hibernate.engine.SessionImplementor session)

		return new Timestamp( System.currentTimeMillis() );
	
public voidset(java.sql.PreparedStatement st, java.lang.Object value, int index)

		Timestamp ts;
		if (value instanceof Timestamp) {
			ts = (Timestamp) value;
		}
		else {
			ts = new Timestamp( ( (java.util.Date) value ).getTime() );
		}
		st.setTimestamp(index, ts);
	
public intsqlType()

		return Types.TIMESTAMP;
	
public java.lang.StringtoString(java.lang.Object val)

		return new SimpleDateFormat(TIMESTAMP_FORMAT).format( (java.util.Date) val );