Open Source Repository

Home /hibernate/hibernate-3.2.7.ga | Repository Home



org/hibernate/type/TimeZoneType.java
//$Id: TimeZoneType.java 7825 2005-08-10 20:23:55Z oneovthafew $
package org.hibernate.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TimeZone;

import org.hibernate.EntityMode;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;

/**
 <tt>timezone</tt>: A type that maps an SQL VARCHAR to a
 <tt>java.util.TimeZone</tt>
 @see java.util.TimeZone
 @author Gavin King
 */
public class TimeZoneType extends ImmutableType implements LiteralType {

  public Object get(ResultSet rs, String name)
  throws HibernateException, SQLException {
    String id = (StringHibernate.STRING.nullSafeGet(rs, name);
    return (id==nullnull : TimeZone.getTimeZone(id);
  }


  public void set(PreparedStatement st, Object value, int indexthrows HibernateException, SQLException {
    Hibernate.STRING.set(st, ( (TimeZonevalue ).getID(), index);
  }

  public int sqlType() {
    return Hibernate.STRING.sqlType();
  }

  public String toString(Object valuethrows HibernateException {
    return ( (TimeZonevalue ).getID();
  }

  public int compare(Object x, Object y, EntityMode entityMode) {
    return ( (TimeZone).getID().compareTo( ( (TimeZone).getID() );
  }

  public Object fromStringValue(String xmlthrows HibernateException {
    return TimeZone.getTimeZone(xml);
  }

  public Class getReturnedClass() {
    return TimeZone.class;
  }

  public String getName() {
    return "timezone";
  }

  public String objectToSQLString(Object value, Dialect dialectthrows Exception {
    return ( (LiteralTypeHibernate.STRING ).objectToSQLString(
      ( (TimeZonevalue ).getID(), dialect
    );
  }

}