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