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 import java.util.Objects;
23
24 import org.jspecify.annotations.Nullable;
25 import org.mybatis.generator.internal.db.DatabaseDialects;
26
27
28
29
30
31
32
33 public class GeneratedKey {
34
35 private final String column;
36 private final String runtimeSqlStatement;
37 private final boolean isIdentity;
38
39 public GeneratedKey(@Nullable String column, @Nullable String configuredSqlStatement, boolean isIdentity) {
40 this.column = Objects.requireNonNull(column);
41 this.isIdentity = isIdentity;
42
43 Objects.requireNonNull(configuredSqlStatement);
44 this.runtimeSqlStatement = DatabaseDialects.getDatabaseDialect(configuredSqlStatement)
45 .map(DatabaseDialects::getIdentityRetrievalStatement)
46 .orElse(configuredSqlStatement);
47 }
48
49 public String getColumn() {
50 return column;
51 }
52
53 public boolean isIdentity() {
54 return isIdentity;
55 }
56
57 public String getRuntimeSqlStatement() {
58 return runtimeSqlStatement;
59 }
60
61 public String getMyBatis3Order() {
62 return isIdentity ? "AFTER" : "BEFORE";
63 }
64
65 public void validate(List<String> errors, String tableName, String contextId) {
66 if (!stringHasValue(runtimeSqlStatement)) {
67 errors.add(getString("ValidationError.7", tableName, contextId));
68 }
69 }
70
71 public boolean isJdbcStandard() {
72 return "JDBC".equals(runtimeSqlStatement);
73 }
74 }