01: /*
02: * Copyright 2004 Clinton Begin
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.ibatis.sqlmap.engine.type;
17:
18: import java.math.BigDecimal;
19: import java.sql.CallableStatement;
20: import java.sql.PreparedStatement;
21: import java.sql.ResultSet;
22: import java.sql.SQLException;
23:
24: /**
25: * BigDecimal implementation of TypeHandler
26: */
27: public class BigDecimalTypeHandler extends BaseTypeHandler implements
28: TypeHandler {
29:
30: public void setParameter(PreparedStatement ps, int i,
31: Object parameter, String jdbcType) throws SQLException {
32: ps.setBigDecimal(i, ((BigDecimal) parameter));
33: }
34:
35: public Object getResult(ResultSet rs, String columnName)
36: throws SQLException {
37: Object bigdec = rs.getBigDecimal(columnName);
38: if (rs.wasNull()) {
39: return null;
40: } else {
41: return bigdec;
42: }
43: }
44:
45: public Object getResult(ResultSet rs, int columnIndex)
46: throws SQLException {
47: Object bigdec = rs.getBigDecimal(columnIndex);
48: if (rs.wasNull()) {
49: return null;
50: } else {
51: return bigdec;
52: }
53: }
54:
55: public Object getResult(CallableStatement cs, int columnIndex)
56: throws SQLException {
57: Object bigdec = cs.getBigDecimal(columnIndex);
58: if (cs.wasNull()) {
59: return null;
60: } else {
61: return bigdec;
62: }
63: }
64:
65: public Object valueOf(String s) {
66: return java.math.BigDecimal
67: .valueOf(Long.valueOf(s).longValue());
68: }
69:
70: }
|