1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.usertype.spi.shared;
17
18 import java.sql.Timestamp;
19 import java.util.Calendar;
20 import java.util.Comparator;
21 import java.util.Date;
22
23 import org.hibernate.HibernateException;
24 import org.hibernate.dialect.Dialect;
25 import org.hibernate.engine.spi.SharedSessionContractImplementor;
26 import org.hibernate.type.AbstractSingleColumnStandardBasicType;
27 import org.hibernate.type.LiteralType;
28 import org.hibernate.type.StringType;
29 import org.hibernate.type.VersionType;
30 import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor;
31 import org.jadira.usertype.spi.shared.descriptor.sql.DstSafeTimestampTypeDescriptor;
32
33
34
35
36 @Deprecated
37 public class DstSafeTimestampType extends
38 AbstractSingleColumnStandardBasicType<Date> implements
39 VersionType<Date>, LiteralType<Date> {
40
41 private static final long serialVersionUID = -3665273920874664942L;
42
43 public static final DstSafeTimestampType INSTANCE = new DstSafeTimestampType();
44
45 public DstSafeTimestampType() {
46 super(DstSafeTimestampTypeDescriptor.INSTANCE,
47 JdbcTimestampTypeDescriptor.INSTANCE);
48 }
49
50 public DstSafeTimestampType(Calendar cal) {
51 super(cal == null ? DstSafeTimestampTypeDescriptor.INSTANCE : new DstSafeTimestampTypeDescriptor(cal),
52 JdbcTimestampTypeDescriptor.INSTANCE);
53 }
54
55 public String getName() {
56 return "dstSafeTimestamp";
57 }
58
59 @Override
60 public String[] getRegistrationKeys() {
61 return new String[] { getName(), Timestamp.class.getName(),
62 java.util.Date.class.getName() };
63 }
64
65 public Date next(Date current, SharedSessionContractImplementor session) {
66 return seed(session);
67 }
68
69 public Date seed(SharedSessionContractImplementor session) {
70 return new Timestamp(System.currentTimeMillis());
71 }
72
73 public Comparator<Date> getComparator() {
74 return getJavaTypeDescriptor().getComparator();
75 }
76
77 public String objectToSQLString(Date value, Dialect dialect)
78 throws Exception {
79 final Timestamp ts = Timestamp.class.isInstance(value) ? (Timestamp) value
80 : new Timestamp(value.getTime());
81
82
83 return StringType.INSTANCE.objectToSQLString(ts.toString(), dialect);
84 }
85
86 public Date fromStringValue(String xml) throws HibernateException {
87 return fromString(xml);
88 }
89 }