1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.generator.config;
17
18 import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
19 import static org.mybatis.generator.internal.util.messages.Messages.getString;
20
21 import java.util.List;
22
23 import org.mybatis.generator.internal.db.DatabaseDialects;
24
25
26
27
28
29
30
31 public class GeneratedKey {
32
33 private final String column;
34
35 private final String runtimeSqlStatement;
36
37 private final boolean isIdentity;
38
39 private final String type;
40
41 public GeneratedKey(String column, String configuredSqlStatement,
42 boolean isIdentity, String type) {
43 super();
44 this.column = column;
45 this.type = type;
46 this.isIdentity = isIdentity;
47
48 DatabaseDialects dialect = DatabaseDialects
49 .getDatabaseDialect(configuredSqlStatement);
50 if (dialect == null) {
51 this.runtimeSqlStatement = configuredSqlStatement;
52 } else {
53 this.runtimeSqlStatement = dialect.getIdentityRetrievalStatement();
54 }
55 }
56
57 public String getColumn() {
58 return column;
59 }
60
61 public boolean isIdentity() {
62 return isIdentity;
63 }
64
65 public String getRuntimeSqlStatement() {
66 return runtimeSqlStatement;
67 }
68
69 public String getMyBatis3Order() {
70 return isIdentity ? "AFTER" : "BEFORE";
71 }
72
73 public void validate(List<String> errors, String tableName) {
74 if (!stringHasValue(runtimeSqlStatement)) {
75 errors.add(getString("ValidationError.7",
76 tableName));
77 }
78
79 if (stringHasValue(type)
80 && !"pre".equals(type)
81 && !"post".equals(type)) {
82 errors.add(getString("ValidationError.15", tableName));
83 }
84
85 if ("pre".equals(type) && isIdentity) {
86 errors.add(getString("ValidationError.23",
87 tableName));
88 }
89
90 if ("post".equals(type) && !isIdentity) {
91 errors.add(getString("ValidationError.24",
92 tableName));
93 }
94 }
95
96 public boolean isJdbcStandard() {
97 return "JDBC".equals(runtimeSqlStatement);
98 }
99 }