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