01: //$Id: BigDecimalType.java 5744 2005-02-16 12:50:19Z oneovthafew $
02: package org.hibernate.type;
03:
04: import java.math.BigDecimal;
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.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 get(ResultSet rs, String name)
22: throws HibernateException, SQLException {
23: return rs.getBigDecimal(name);
24: }
25:
26: public void set(PreparedStatement st, Object value, int index)
27: throws HibernateException, SQLException {
28: st.setBigDecimal(index, (BigDecimal) value);
29: }
30:
31: public int sqlType() {
32: return Types.NUMERIC;
33: }
34:
35: public String toString(Object value) throws HibernateException {
36: return value.toString();
37: }
38:
39: public Class getReturnedClass() {
40: return BigDecimal.class;
41: }
42:
43: public boolean isEqual(Object x, Object y) {
44: return x == y
45: || (x != null && y != null && ((BigDecimal) x)
46: .compareTo((BigDecimal) y) == 0);
47: }
48:
49: public int getHashCode(Object x, EntityMode entityMode) {
50: return ((BigDecimal) x).intValue();
51: }
52:
53: public String getName() {
54: return "big_decimal";
55: }
56:
57: public Object fromStringValue(String xml) {
58: return new BigDecimal(xml);
59: }
60:
61: }
|