Want more features on Pastebin? Sign Up, it's FREE!
Guest

Hibernate/Timestamp - DateTimestampType

By: nickmz on Jul 13th, 2011  |  syntax: Java  |  size: 1.49 KB  |  views: 173  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package xxx;
  2.  
  3. import org.hibernate.HibernateException;
  4. import org.hibernate.dialect.Dialect;
  5. import org.hibernate.engine.SessionImplementor;
  6. import org.hibernate.type.AbstractSingleColumnStandardBasicType;
  7. import org.hibernate.type.LiteralType;
  8. import org.hibernate.type.StringType;
  9. import org.hibernate.type.VersionType;
  10. import org.hibernate.type.descriptor.sql.TimestampTypeDescriptor;
  11.  
  12. import java.util.Comparator;
  13. import java.util.Date;
  14.  
  15. public class DateTimestampType
  16.         extends AbstractSingleColumnStandardBasicType<Date>
  17.                 implements VersionType<Date>, LiteralType<Date> {
  18.  
  19.     public static final DateTimestampType INSTANCE = new DateTimestampType();
  20.  
  21.     public DateTimestampType() {
  22.         super(TimestampTypeDescriptor.INSTANCE, JdbcDateTimestampTypeDescriptor.INSTANCE);
  23.     }
  24.  
  25.     public String getName() {
  26.         return "timestamp";
  27.     }
  28.  
  29.     public Date next(Date current, SessionImplementor session) {
  30.         return seed(session);
  31.     }
  32.  
  33.     public Date seed(SessionImplementor session) {
  34.         return new Date(System.currentTimeMillis());
  35.     }
  36.  
  37.     public Comparator<Date> getComparator() {
  38.         return getJavaTypeDescriptor().getComparator();
  39.     }
  40.  
  41.     public String objectToSQLString(Date value, Dialect dialect) throws Exception {
  42.         return StringType.INSTANCE.objectToSQLString( value.toString(), dialect );
  43.     }
  44.  
  45.     public Date fromStringValue(String xml) throws HibernateException {
  46.         return fromString( xml );
  47.     }
  48.  
  49.  
  50.  
  51. }
clone this paste RAW Paste Data