01: //$Id: StringType.java 7825 2005-08-10 20:23:55Z oneovthafew $
02: package org.hibernate.type;
03:
04: import java.sql.PreparedStatement;
05: import java.sql.ResultSet;
06: import java.sql.SQLException;
07: import java.sql.Types;
08:
09: import org.hibernate.dialect.Dialect;
10:
11: /**
12: * <tt>string</tt>: A type that maps an SQL VARCHAR to a Java String.
13: * @author Gavin King
14: */
15: public class StringType extends ImmutableType implements
16: DiscriminatorType {
17:
18: public Object get(ResultSet rs, String name) throws SQLException {
19: return rs.getString(name);
20: }
21:
22: public Class getReturnedClass() {
23: return String.class;
24: }
25:
26: public void set(PreparedStatement st, Object value, int index)
27: throws SQLException {
28: st.setString(index, (String) value);
29: }
30:
31: public int sqlType() {
32: return Types.VARCHAR;
33: }
34:
35: public String getName() {
36: return "string";
37: }
38:
39: public String objectToSQLString(Object value, Dialect dialect)
40: throws Exception {
41: return '\'' + (String) value + '\'';
42: }
43:
44: public Object stringToObject(String xml) throws Exception {
45: return xml;
46: }
47:
48: public String toString(Object value) {
49: return (String) value;
50: }
51:
52: public Object fromStringValue(String xml) {
53: return xml;
54: }
55:
56: }
|