KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.ibatis.sqlmap.client.extensions.ParameterSetter;
19 import com.ibatis.sqlmap.client.extensions.ResultGetter;
20 import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
21
22 import java.sql.CallableStatement JavaDoc;
23 import java.sql.PreparedStatement JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 /**
28  * Custom type handler for adding a TypeHandlerCallback
29  */

30 public class CustomTypeHandler extends BaseTypeHandler implements TypeHandler {
31
32   private TypeHandlerCallback callback;
33
34   /**
35    * Constructor to provide a TypeHandlerCallback instance
36    *
37    * @param callback - the TypeHandlerCallback instance
38    */

39   public CustomTypeHandler(TypeHandlerCallback callback) {
40     this.callback = callback;
41   }
42
43   public void setParameter(PreparedStatement JavaDoc ps, int i, Object JavaDoc parameter, String JavaDoc jdbcType)
44       throws SQLException JavaDoc {
45     ParameterSetter setter = new ParameterSetterImpl(ps, i);
46     callback.setParameter(setter, parameter);
47   }
48
49   public Object JavaDoc getResult(ResultSet JavaDoc rs, String JavaDoc columnName)
50       throws SQLException JavaDoc {
51     ResultGetter getter = new ResultGetterImpl(rs, columnName);
52     return callback.getResult(getter);
53   }
54
55   public Object JavaDoc getResult(ResultSet JavaDoc rs, int columnIndex)
56       throws SQLException JavaDoc {
57     ResultGetter getter = new ResultGetterImpl(rs, columnIndex);
58     return callback.getResult(getter);
59   }
60
61   public Object JavaDoc getResult(CallableStatement JavaDoc cs, int columnIndex)
62       throws SQLException JavaDoc {
63     ResultGetter getter = new ResultGetterImpl(new CallableStatementResultSet(cs), columnIndex);
64     return callback.getResult(getter);
65   }
66
67   public Object JavaDoc valueOf(String JavaDoc s) {
68     return callback.valueOf(s);
69   }
70
71 }
72
Popular Tags