KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.CallableStatement JavaDoc;
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21 import java.sql.SQLException JavaDoc;
22
23 /**
24  * Integer Decimal implementation of TypeHandler
25  */

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