1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.type;
17
18 import java.sql.CallableStatement;
19 import java.sql.PreparedStatement;
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22 import java.util.HashSet;
23 import java.util.Set;
24 import java.util.stream.Collectors;
25
26 import org.apache.ibatis.executor.ExecutorException;
27
28 public class ConflictedTypeHandler implements TypeHandler<Object> {
29
30 private final Class<?> javaType;
31 private final JdbcType jdbcType;
32 private final Set<TypeHandler<?>> conflictedTypeHandlers = new HashSet<>();
33
34 public ConflictedTypeHandler(Class<?> javaType, JdbcType jdbcType, TypeHandler<?> existing, TypeHandler<?> added) {
35 super();
36 this.javaType = javaType;
37 this.jdbcType = jdbcType;
38 if (existing instanceof ConflictedTypeHandler) {
39 conflictedTypeHandlers.addAll(((ConflictedTypeHandler) existing).getConflictedTypeHandlers());
40 } else {
41 conflictedTypeHandlers.add(existing);
42 }
43 conflictedTypeHandlers.add(added);
44 }
45
46 private Set<TypeHandler<?>> getConflictedTypeHandlers() {
47 return conflictedTypeHandlers;
48 }
49
50 @Override
51 public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
52 throw exception();
53 }
54
55 @Override
56 public Object getResult(ResultSet rs, String columnName) throws SQLException {
57 throw exception();
58 }
59
60 @Override
61 public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
62 throw exception();
63 }
64
65 @Override
66 public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
67 throw exception();
68 }
69
70 private ExecutorException exception() {
71 return new ExecutorException(
72 "Multiple type-aware handlers are registered and being looked up without type; javaType=" + javaType
73 + ", jdbcType=" + jdbcType + ", type handlers="
74 + conflictedTypeHandlers.stream().map(x -> x.getClass().getName()).collect(Collectors.joining(",")));
75 }
76 }