KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: FloatType.java,v 1.2 2004/09/11 11:29:23 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.io.Serializable JavaDoc;
5 import java.sql.PreparedStatement JavaDoc;
6 import java.sql.ResultSet JavaDoc;
7 import java.sql.SQLException JavaDoc;
8 import java.sql.Types JavaDoc;
9
10 /**
11  * <tt>float</tt>: A type that maps an SQL FLOAT to a Java Float.
12  * @author Gavin King
13  */

14 public class FloatType extends PrimitiveType {
15
16     public Serializable JavaDoc getDefaultValue() {
17         return new Float JavaDoc(0.0);
18     }
19     
20     public Object JavaDoc get(ResultSet JavaDoc rs, String JavaDoc name) throws SQLException JavaDoc {
21         return new Float JavaDoc( rs.getFloat(name) );
22     }
23
24     public Class JavaDoc getPrimitiveClass() {
25         return float.class;
26     }
27
28     public Class JavaDoc getReturnedClass() {
29         return Float JavaDoc.class;
30     }
31
32     public void set(PreparedStatement JavaDoc st, Object JavaDoc value, int index)
33     throws SQLException JavaDoc {
34
35         st.setFloat( index, ( (Float JavaDoc) value ).floatValue() );
36     }
37
38     public int sqlType() {
39         return Types.FLOAT;
40     }
41
42     public String JavaDoc getName() { return "float"; }
43
44     public String JavaDoc objectToSQLString(Object JavaDoc value) throws Exception JavaDoc {
45         return value.toString();
46     }
47
48     public Object JavaDoc fromStringValue(String JavaDoc xml) {
49         return new Float JavaDoc(xml);
50     }
51
52 }
53
54
55
56
57
58
Popular Tags