~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/type/TimeZoneType.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: TimeZoneType.java 7825 2005-08-10 20:23:55Z oneovthafew $
 
2
package org.hibernate.type;
 
3
 
 
4
import java.sql.PreparedStatement;
 
5
import java.sql.ResultSet;
 
6
import java.sql.SQLException;
 
7
import java.util.TimeZone;
 
8
 
 
9
import org.hibernate.EntityMode;
 
10
import org.hibernate.Hibernate;
 
11
import org.hibernate.HibernateException;
 
12
import org.hibernate.dialect.Dialect;
 
13
 
 
14
/**
 
15
 * <tt>timezone</tt>: A type that maps an SQL VARCHAR to a
 
16
 * <tt>java.util.TimeZone</tt>
 
17
 * @see java.util.TimeZone
 
18
 * @author Gavin King
 
19
 */
 
20
public class TimeZoneType extends ImmutableType implements LiteralType {
 
21
 
 
22
        public Object get(ResultSet rs, String name)
 
23
        throws HibernateException, SQLException {
 
24
                String id = (String) Hibernate.STRING.nullSafeGet(rs, name);
 
25
                return (id==null) ? null : TimeZone.getTimeZone(id);
 
26
        }
 
27
 
 
28
 
 
29
        public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
 
30
                Hibernate.STRING.set(st, ( (TimeZone) value ).getID(), index);
 
31
        }
 
32
 
 
33
        public int sqlType() {
 
34
                return Hibernate.STRING.sqlType();
 
35
        }
 
36
 
 
37
        public String toString(Object value) throws HibernateException {
 
38
                return ( (TimeZone) value ).getID();
 
39
        }
 
40
 
 
41
        public int compare(Object x, Object y, EntityMode entityMode) {
 
42
                return ( (TimeZone) x ).getID().compareTo( ( (TimeZone) y ).getID() );
 
43
        }
 
44
 
 
45
        public Object fromStringValue(String xml) throws HibernateException {
 
46
                return TimeZone.getTimeZone(xml);
 
47
        }
 
48
 
 
49
        public Class getReturnedClass() {
 
50
                return TimeZone.class;
 
51
        }
 
52
 
 
53
        public String getName() {
 
54
                return "timezone";
 
55
        }
 
56
 
 
57
        public String objectToSQLString(Object value, Dialect dialect) throws Exception {
 
58
                return ( (LiteralType) Hibernate.STRING ).objectToSQLString(
 
59
                        ( (TimeZone) value ).getID(), dialect
 
60
                );
 
61
        }
 
62
 
 
63
}
 
64
 
 
65
 
 
66
 
 
67
 
 
68
 
 
69