1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
25
26 public class UnknownTypeHandler extends BaseTypeHandler implements TypeHandler {
27
28
29 private TypeHandlerFactory factory;
30
31
32
33
34
35
36
37 public UnknownTypeHandler(TypeHandlerFactory factory) {
38 this.factory = factory;
39 }
40
41 public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) throws SQLException {
42 Class searchClass = parameter.getClass();
43 if (searchClass == null) {
44 searchClass = parameter.getClass();
45 }
46 TypeHandler handler = factory.getTypeHandler(searchClass, jdbcType);
47 handler.setParameter(ps, i, parameter, jdbcType);
48 }
49
50 public Object getResult(ResultSet rs, String columnName) throws SQLException {
51 Object object = rs.getObject(columnName);
52 if (rs.wasNull()) {
53 return null;
54 } else {
55 return object;
56 }
57 }
58
59 public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
60 Object object = rs.getObject(columnIndex);
61 if (rs.wasNull()) {
62 return null;
63 } else {
64 return object;
65 }
66 }
67
68 public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
69 Object object = cs.getObject(columnIndex);
70 if (cs.wasNull()) {
71 return null;
72 } else {
73 return object;
74 }
75 }
76
77 public Object valueOf(String s) {
78 return s;
79 }
80
81 @Override
82 public boolean equals(Object object, String string) {
83 if (object == null || string == null) {
84 return object == string;
85 } else {
86 TypeHandler handler = factory.getTypeHandler(object.getClass());
87 Object castedObject = handler.valueOf(string);
88 return object.equals(castedObject);
89 }
90 }
91
92 }