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 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;
23: import java.sql.PreparedStatement;
24: import java.sql.ResultSet;
25: import java.sql.SQLException;
26:
27: /**
28: * Custom type handler for adding a TypeHandlerCallback
29: */
30: public class CustomTypeHandler extends BaseTypeHandler implements
31: TypeHandler {
32:
33: private TypeHandlerCallback callback;
34:
35: /**
36: * Constructor to provide a TypeHandlerCallback instance
37: *
38: * @param callback - the TypeHandlerCallback instance
39: */
40: public CustomTypeHandler(TypeHandlerCallback callback) {
41: this .callback = callback;
42: }
43:
44: public void setParameter(PreparedStatement ps, int i,
45: Object parameter, String jdbcType) throws SQLException {
46: ParameterSetter setter = new ParameterSetterImpl(ps, i);
47: callback.setParameter(setter, parameter);
48: }
49:
50: public Object getResult(ResultSet rs, String columnName)
51: throws SQLException {
52: ResultGetter getter = new ResultGetterImpl(rs, columnName);
53: return callback.getResult(getter);
54: }
55:
56: public Object getResult(ResultSet rs, int columnIndex)
57: throws SQLException {
58: ResultGetter getter = new ResultGetterImpl(rs, columnIndex);
59: return callback.getResult(getter);
60: }
61:
62: public Object getResult(CallableStatement cs, int columnIndex)
63: throws SQLException {
64: ResultGetter getter = new ResultGetterImpl(
65: new CallableStatementResultSet(cs), columnIndex);
66: return callback.getResult(getter);
67: }
68:
69: public Object valueOf(String s) {
70: return callback.valueOf(s);
71: }
72:
73: }
|