1 /*
2 * Copyright 2004-2022 the original author or authors.
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 * https://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;
19 import java.sql.PreparedStatement;
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22
23 /**
24 * Interface for getting data into, and out of a mapped statement.
25 */
26 public interface TypeHandler {
27
28 /**
29 * Sets a parameter on a prepared statement.
30 *
31 * @param ps
32 * - the prepared statement
33 * @param i
34 * - the parameter index
35 * @param parameter
36 * - the parameter value
37 * @param jdbcType
38 * - the JDBC type of the parameter
39 *
40 * @throws SQLException
41 * if setting the parameter fails
42 */
43 public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) throws SQLException;
44
45 /**
46 * Gets a column from a result set.
47 *
48 * @param rs
49 * - the result set
50 * @param columnName
51 * - the column name to get
52 *
53 * @return - the column value
54 *
55 * @throws SQLException
56 * if getting the value fails
57 */
58 public Object getResult(ResultSet rs, String columnName) throws SQLException;
59
60 /**
61 * Gets a column from a result set.
62 *
63 * @param rs
64 * - the result set
65 * @param columnIndex
66 * - the column to get (by index)
67 *
68 * @return - the column value
69 *
70 * @throws SQLException
71 * if getting the value fails
72 */
73 public Object getResult(ResultSet rs, int columnIndex) throws SQLException;
74
75 /**
76 * Gets a column from a callable statement.
77 *
78 * @param cs
79 * - the statement
80 * @param columnIndex
81 * - the column to get (by index)
82 *
83 * @return - the column value
84 *
85 * @throws SQLException
86 * if getting the value fails
87 */
88 public Object getResult(CallableStatement cs, int columnIndex) throws SQLException;
89
90 /**
91 * Converts the String to the type that this handler deals with.
92 *
93 * @param s
94 * - the String value
95 *
96 * @return - the converted value
97 */
98 public Object valueOf(String s);
99
100 /**
101 * Compares two values (that this handler deals with) for equality.
102 *
103 * @param object
104 * - one of the objects
105 * @param string
106 * - the other object as a String
107 *
108 * @return - true if they are equal
109 */
110 public boolean equals(Object object, String string);
111
112 }