From: <one...@us...> - 2002-11-21 09:05:06
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/type In directory sc8-pr-cvs1:/tmp/cvs-serv4317/cirrus/hibernate/type Added Files: CalendarType.java Log Message: calendar types --- NEW FILE: CalendarType.java --- //$Id: CalendarType.java,v 1.1 2002/11/21 09:05:03 oneovthafew Exp $ package cirrus.hibernate.type; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; import java.util.Calendar; import java.util.GregorianCalendar; import cirrus.hibernate.HibernateException; /** * A type mapping for a <tt>Calendar</tt> object that represents a datetime. */ public class CalendarType extends MutableType { /** * @see cirrus.hibernate.type.NullableType#get(ResultSet, String) */ public Object get(ResultSet rs, String name) throws HibernateException, SQLException { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis( rs.getTimestamp(name).getTime() ); return cal; } /** * @see cirrus.hibernate.type.NullableType#set(PreparedStatement, Object, int) */ public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { st.setTimestamp( index, new Timestamp( ( (Calendar) value ).getTimeInMillis() ) ); } /** * @see cirrus.hibernate.type.NullableType#sqlType() */ public int sqlType() { return Types.TIMESTAMP; } /** * @see cirrus.hibernate.type.NullableType#toXML(Object) */ public String toXML(Object value) throws HibernateException { //TODO: return value.toString(); } /** * @see cirrus.hibernate.type.NullableType#deepCopyNotNull(Object) */ public Object deepCopyNotNull(Object value) throws HibernateException { return ( (Calendar) value ).clone(); } /** * @see cirrus.hibernate.type.Type#returnedClass() */ public Class returnedClass() { return Calendar.class; } /** * @see cirrus.hibernate.type.Type#equals(Object, Object) */ public boolean equals(Object x, Object y) throws HibernateException { if (x==y) return true; if (x==null || y==null) return false; Calendar calendar1 = (Calendar) x; Calendar calendar2 = (Calendar) y; return calendar1.get(Calendar.MILLISECOND) == calendar2.get(Calendar.MILLISECOND) && calendar1.get(Calendar.SECOND) == calendar2.get(Calendar.SECOND) && calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE) && calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY) && calendar1.get(Calendar.DAY_OF_MONTH) == calendar2.get(Calendar.DAY_OF_MONTH) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH) && calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR); } /** * @see cirrus.hibernate.type.Type#getName() */ public String getName() { return "calendar"; } } |