Save This Page
Home » Hibernate-3.3.2.GA » org.hibernate » type » [javadoc | source]
    1   /*
    2    * Hibernate, Relational Persistence for Idiomatic Java
    3    *
    4    * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
    5    * indicated by the @author tags or express copyright attribution
    6    * statements applied by the authors.  All third-party contributions are
    7    * distributed under license by Red Hat Middleware LLC.
    8    *
    9    * This copyrighted material is made available to anyone wishing to use, modify,
   10    * copy, or redistribute it subject to the terms and conditions of the GNU
   11    * Lesser General Public License, as published by the Free Software Foundation.
   12    *
   13    * This program is distributed in the hope that it will be useful,
   14    * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15    * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   16    * for more details.
   17    *
   18    * You should have received a copy of the GNU Lesser General Public License
   19    * along with this distribution; if not, write to:
   20    * Free Software Foundation, Inc.
   21    * 51 Franklin Street, Fifth Floor
   22    * Boston, MA  02110-1301  USA
   23    *
   24    */
   25   package org.hibernate.type;
   26   
   27   import java.sql.PreparedStatement;
   28   import java.sql.ResultSet;
   29   import java.sql.SQLException;
   30   import java.sql.Types;
   31   
   32   import org.hibernate.dialect.Dialect;
   33   
   34   /**
   35    * <tt>string</tt>: A type that maps an SQL VARCHAR to a Java String.
   36    * @author Gavin King
   37    */
   38   public class StringType extends ImmutableType implements DiscriminatorType {
   39   
   40   	public Object get(ResultSet rs, String name) throws SQLException {
   41   		return rs.getString(name);
   42   	}
   43   
   44   	public Class getReturnedClass() {
   45   		return String.class;
   46   	}
   47   
   48   	public void set(PreparedStatement st, Object value, int index) throws SQLException {
   49   		st.setString(index, (String) value);
   50   	}
   51   
   52   	public int sqlType() {
   53   		return Types.VARCHAR;
   54   	}
   55   
   56   	public String getName() { return "string"; }
   57   
   58   	public String objectToSQLString(Object value, Dialect dialect) throws Exception {
   59   		return '\'' + (String) value + '\'';
   60   	}
   61   
   62   	public Object stringToObject(String xml) throws Exception {
   63   		return xml;
   64   	}
   65   
   66   	public String toString(Object value) {
   67   		return (String) value;
   68   	}
   69   
   70   	public Object fromStringValue(String xml) {
   71   		return xml;
   72   	}
   73   
   74   }
   75   
   76   
   77   
   78   
   79   

Save This Page
Home » Hibernate-3.3.2.GA » org.hibernate » type » [javadoc | source]