KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: DoubleType.java,v 1.2 2004/09/11 11:29:23 oneovthafew Exp $
2
package org.hibernate.type;
3 import java.io.Serializable JavaDoc;
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>double</tt>: A type that maps an SQL DOUBLE to a Java Double.
11  * @author Gavin King
12  */

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