KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: BigDecimalType.java,v 1.4 2005/02/16 12:50:18 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.math.BigDecimal 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 import org.hibernate.EntityMode;
11 import org.hibernate.HibernateException;
12
13 /**
14  * <tt>big_decimal</tt>: A type that maps an SQL NUMERIC to a
15  * <tt>java.math.BigDecimal</tt>
16  * @see java.math.BigDecimal
17  * @author Gavin King
18  */

19 public class BigDecimalType extends ImmutableType {
20
21     public Object JavaDoc get(ResultSet JavaDoc rs, String JavaDoc name)
22     throws HibernateException, SQLException JavaDoc {
23         return rs.getBigDecimal(name);
24     }
25
26     public void set(PreparedStatement JavaDoc st, Object JavaDoc value, int index)
27     throws HibernateException, SQLException JavaDoc {
28         st.setBigDecimal(index, (BigDecimal JavaDoc) value);
29     }
30
31     public int sqlType() {
32         return Types.NUMERIC;
33     }
34
35     public String JavaDoc toString(Object JavaDoc value) throws HibernateException {
36         return value.toString();
37     }
38
39     public Class JavaDoc getReturnedClass() {
40         return BigDecimal JavaDoc.class;
41     }
42
43     public boolean isEqual(Object JavaDoc x, Object JavaDoc y) {
44         return x==y || ( x!=null && y!=null && ( (BigDecimal JavaDoc) x ).compareTo( (BigDecimal JavaDoc) y )==0 );
45     }
46
47     public int getHashCode(Object JavaDoc x, EntityMode entityMode) {
48         return ( (BigDecimal JavaDoc) x ).intValue();
49     }
50
51     public String JavaDoc getName() {
52         return "big_decimal";
53     }
54
55     public Object JavaDoc fromStringValue(String JavaDoc xml) {
56         return new BigDecimal JavaDoc(xml);
57     }
58
59
60 }
61
62
63
64
65
66
67
Popular Tags