KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > type > BigDecimalTypeHandler


1 /*
2  * Copyright 2004 Clinton Begin
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.sql.CallableStatement JavaDoc;
20 import java.sql.PreparedStatement JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.SQLException JavaDoc;
23
24 /**
25  * BigDecimal implementation of TypeHandler
26  */

27 public class BigDecimalTypeHandler extends BaseTypeHandler implements TypeHandler {
28
29   public void setParameter(PreparedStatement JavaDoc ps, int i, Object JavaDoc parameter, String JavaDoc jdbcType)
30       throws SQLException JavaDoc {
31     ps.setBigDecimal(i, ((BigDecimal JavaDoc) parameter));
32   }
33
34   public Object JavaDoc getResult(ResultSet JavaDoc rs, String JavaDoc columnName)
35       throws SQLException JavaDoc {
36     Object JavaDoc bigdec = rs.getBigDecimal(columnName);
37     if (rs.wasNull()) {
38       return null;
39     } else {
40       return bigdec;
41     }
42   }
43
44   public Object JavaDoc getResult(ResultSet JavaDoc rs, int columnIndex)
45       throws SQLException JavaDoc {
46     Object JavaDoc bigdec = rs.getBigDecimal(columnIndex);
47     if (rs.wasNull()) {
48       return null;
49     } else {
50       return bigdec;
51     }
52   }
53
54   public Object JavaDoc getResult(CallableStatement JavaDoc cs, int columnIndex)
55       throws SQLException JavaDoc {
56     Object JavaDoc bigdec = cs.getBigDecimal(columnIndex);
57     if (cs.wasNull()) {
58       return null;
59     } else {
60       return bigdec;
61     }
62   }
63
64   public Object JavaDoc valueOf(String JavaDoc s) {
65     return java.math.BigDecimal.valueOf(Long.valueOf(s).longValue());
66   }
67
68 }
69
Popular Tags