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 public enum AutoMappingUnknownColumnBehavior {
29
30
31
32
33 NONE {
34 @Override
35 public void doAction(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
36
37 }
38 },
39
40
41
42
43
44 WARNING {
45 @Override
46 public void doAction(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
47 LogHolder.log.warn(buildMessage(mappedStatement, columnName, property, propertyType));
48 }
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 public abstract void doAction(MappedStatement mappedStatement, String columnName, String propertyName, Class<?> propertyType);
70
71
72
73
74 private static String buildMessage(MappedStatement mappedStatement, String columnName, String property, Class<?> propertyType) {
75 return new StringBuilder("Unknown column is detected on '")
76 .append(mappedStatement.getId())
77 .append("' auto-mapping. Mapping parameters are ")
78 .append("[")
79 .append("columnName=").append(columnName)
80 .append(",").append("propertyName=").append(property)
81 .append(",").append("propertyType=").append(propertyType != null ? propertyType.getName() : null)
82 .append("]")
83 .toString();
84 }
85
86 private static class LogHolder {
87 private static final Log log = LogFactory.getLog(AutoMappingUnknownColumnBehavior.class);
88 }
89
90 }