KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > TimeZoneType


1 //$Id: TimeZoneType.java,v 1.4 2005/02/16 12:50:19 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.util.TimeZone JavaDoc;
8
9 import org.hibernate.EntityMode;
10 import org.hibernate.Hibernate;
11 import org.hibernate.HibernateException;
12
13 /**
14  * <tt>timezone</tt>: A type that maps an SQL VARCHAR to a
15  * <tt>java.util.TimeZone</tt>
16  * @see java.util.TimeZone
17  * @author Gavin King
18  */

19 public class TimeZoneType extends ImmutableType implements LiteralType {
20
21     public Object JavaDoc get(ResultSet JavaDoc rs, String JavaDoc name)
22     throws HibernateException, SQLException JavaDoc {
23         String JavaDoc id = (String JavaDoc) Hibernate.STRING.nullSafeGet(rs, name);
24         return (id==null) ? null : TimeZone.getTimeZone(id);
25     }
26
27
28     public void set(PreparedStatement JavaDoc st, Object JavaDoc value, int index) throws HibernateException, SQLException JavaDoc {
29         Hibernate.STRING.set(st, ( (TimeZone JavaDoc) value ).getID(), index);
30     }
31
32     public int sqlType() {
33         return Hibernate.STRING.sqlType();
34     }
35
36     public String JavaDoc toString(Object JavaDoc value) throws HibernateException {
37         return ( (TimeZone JavaDoc) value ).getID();
38     }
39
40     public int compare(Object JavaDoc x, Object JavaDoc y, EntityMode entityMode) {
41         return ( (TimeZone JavaDoc) x ).getID().compareTo( ( (TimeZone JavaDoc) y ).getID() );
42     }
43
44     public Object JavaDoc fromStringValue(String JavaDoc xml) throws HibernateException {
45         return TimeZone.getTimeZone(xml);
46     }
47
48     public Class JavaDoc getReturnedClass() {
49         return TimeZone JavaDoc.class;
50     }
51
52     public String JavaDoc getName() {
53         return "timezone";
54     }
55
56     public String JavaDoc objectToSQLString(Object JavaDoc value) throws Exception JavaDoc {
57         return ( (LiteralType) Hibernate.STRING ).objectToSQLString(
58             ( (TimeZone JavaDoc) value ).getID()
59         );
60     }
61
62 }
63
64
65
66
67
68
69
Popular Tags