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.util.Calendar;
19 import java.util.Date;
20
21 import org.hibernate.dialect.Dialect;
22 import org.hibernate.type.AbstractSingleColumnStandardBasicType;
23 import org.hibernate.type.IdentifierType;
24 import org.hibernate.type.LiteralType;
25 import org.hibernate.type.StringType;
26 import org.hibernate.type.descriptor.java.JdbcDateTypeDescriptor;
27 import org.jadira.usertype.spi.shared.descriptor.sql.DstSafeDateTypeDescriptor;
28
29
30
31
32 @Deprecated
33 public class DstSafeDateType
34 extends AbstractSingleColumnStandardBasicType<Date>
35 implements IdentifierType<Date>, LiteralType<Date> {
36
37 private static final long serialVersionUID = 669738618020424223L;
38
39 public static final DstSafeDateType INSTANCE = new DstSafeDateType();
40
41 public DstSafeDateType() {
42 super(DstSafeDateTypeDescriptor.INSTANCE,
43 JdbcDateTypeDescriptor.INSTANCE);
44 }
45
46 public DstSafeDateType(Calendar cal) {
47 super(cal == null ? DstSafeDateTypeDescriptor.INSTANCE : new DstSafeDateTypeDescriptor(cal),
48 JdbcDateTypeDescriptor.INSTANCE);
49 }
50 public String getName() {
51 return "dstSafeDate";
52 }
53
54 @Override
55 public String[] getRegistrationKeys() {
56 return new String[] {
57 getName(),
58 java.sql.Date.class.getName()
59 };
60 }
61
62 public String objectToSQLString(Date value, Dialect dialect) throws Exception {
63 final java.sql.Date jdbcDate = java.sql.Date.class.isInstance( value )
64 ? ( java.sql.Date ) value
65 : new java.sql.Date( value.getTime() );
66
67 return StringType.INSTANCE.objectToSQLString( jdbcDate.toString(), dialect );
68 }
69
70 public Date stringToObject(String xml) {
71 return fromString( xml );
72 }
73 }