View Javadoc
1   /*
2    *  Copyright 2013 Christopher Pheby
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.jadira.usertype.spi.shared;
17  
18  import java.sql.Time;
19  import java.util.Calendar;
20  import java.util.Date;
21  
22  import org.hibernate.dialect.Dialect;
23  import org.hibernate.type.AbstractSingleColumnStandardBasicType;
24  import org.hibernate.type.LiteralType;
25  import org.hibernate.type.StringType;
26  import org.hibernate.type.descriptor.java.JdbcTimeTypeDescriptor;
27  import org.jadira.usertype.spi.shared.descriptor.sql.DstSafeTimeTypeDescriptor;
28  
29  /**
30   * @deprecated This class should no longer be used now that Hibernate allows configuration of  hibernate.jdbc.time_zone configuration property 
31   */
32  @Deprecated
33  public class DstSafeTimeType extends
34  		AbstractSingleColumnStandardBasicType<Date> implements
35  		LiteralType<Date> {
36  
37  	private static final long serialVersionUID = -3665273920874664942L;
38  
39  	public static final DstSafeTimeType INSTANCE = new DstSafeTimeType();
40  
41  	public DstSafeTimeType() {
42  		super(DstSafeTimeTypeDescriptor.INSTANCE,
43  				JdbcTimeTypeDescriptor.INSTANCE);
44  	}
45  	
46  	public DstSafeTimeType(Calendar cal) {
47  		super(cal == null ? DstSafeTimeTypeDescriptor.INSTANCE : new DstSafeTimeTypeDescriptor(cal),
48  				JdbcTimeTypeDescriptor.INSTANCE);
49  	}
50  
51  	public String getName() {
52  		return "dstSafeTime";
53  	}
54  
55  	@Override
56  	public String[] getRegistrationKeys() {
57  		return new String[] { getName(), java.sql.Time.class.getName() };
58  	}
59  
60  	public String objectToSQLString(Date value, Dialect dialect)
61  			throws Exception {
62  		final Time ts = Time.class.isInstance(value) ? (Time) value : new Time(
63  				value.getTime());
64  		// TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in
65  		// yyyy-mm-dd hh:mm:ss[.f...] format
66  		return StringType.INSTANCE.objectToSQLString(ts.toString(), dialect);
67  	}
68  }