1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.session;
17
18 import org.apache.ibatis.logging.Log;
19 import org.apache.ibatis.logging.LogFactory;
20 import org.apache.ibatis.mapping.MappedStatement;
21
22
23
24
25
26
27
28
29 public enum AutoMappingUnknownColumnBehavior {
30
31
32
33
34 NONE {
35 @Override
36 public void doAction(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
37
38 }
39 },
40
41
42
43
44
45 WARNING {
46 @Override
47 public void doAction(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
48 LogHolder.log.warn(buildMessage(mappedStatement, columnName, property, propertyType));
49 }
50 },
51
52
53
54
55 FAILING {
56 @Override
57 public void doAction(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
58 throw new SqlSessionException(buildMessage(mappedStatement, columnName, property, propertyType));
59 }
60 };
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public abstract void doAction(MappedStatement mappedStatement, String columnName, String propertyName,
76 Class<?> propertyType);
77
78
79
80
81 private static String buildMessage(MappedStatement mappedStatement, String columnName, String property,
82 Class<?> propertyType) {
83 return new StringBuilder("Unknown column is detected on '").append(mappedStatement.getId())
84 .append("' auto-mapping. Mapping parameters are ").append("[").append("columnName=").append(columnName)
85 .append(",").append("propertyName=").append(property).append(",").append("propertyType=")
86 .append(propertyType != null ? propertyType.getName() : null).append("]").toString();
87 }
88
89 private static class LogHolder {
90 private static final Log log = LogFactory.getLog(AutoMappingUnknownColumnBehavior.class);
91 }
92
93 }