KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > StringType


1 //$Id: StringType.java,v 1.2 2004/09/25 11:22:19 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.sql.Types JavaDoc;
8
9 /**
10  * <tt>string</tt>: A type that maps an SQL VARCHAR to a Java String.
11  * @author Gavin King
12  */

13 public class StringType extends ImmutableType implements DiscriminatorType {
14
15     public Object JavaDoc get(ResultSet JavaDoc rs, String JavaDoc name) throws SQLException JavaDoc {
16         return rs.getString(name);
17     }
18
19     public Class JavaDoc getReturnedClass() {
20         return String JavaDoc.class;
21     }
22
23     public void set(PreparedStatement JavaDoc st, Object JavaDoc value, int index) throws SQLException JavaDoc {
24         st.setString(index, (String JavaDoc) value);
25     }
26
27     public int sqlType() {
28         return Types.VARCHAR;
29     }
30
31     public String JavaDoc getName() { return "string"; }
32
33     public String JavaDoc objectToSQLString(Object JavaDoc value) throws Exception JavaDoc {
34         return '\'' + (String JavaDoc) value + '\'';
35     }
36
37     public Object JavaDoc stringToObject(String JavaDoc xml) throws Exception JavaDoc {
38         return xml;
39     }
40
41     public String JavaDoc toString(Object JavaDoc value) {
42         return (String JavaDoc) value;
43     }
44
45     public Object JavaDoc fromStringValue(String JavaDoc xml) {
46         return xml;
47     }
48
49 }
50
51
52
53
54
55
Popular Tags