• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / generator / 1942

12 Jan 2026 05:01PM UTC coverage: 88.75% (+0.4%) from 88.365%
1942

push

github

web-flow
Merge pull request #1412 from jeffgbutler/jspecify

Adopt JSpecify

2331 of 3162 branches covered (73.72%)

1800 of 1949 new or added lines in 202 files covered. (92.36%)

18 existing lines in 10 files now uncovered.

11384 of 12827 relevant lines covered (88.75%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/config/GeneratedKey.java
1
/*
2
 *    Copyright 2006-2026 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
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
 * This class specifies that a key is auto-generated, either as an identity
29
 * column (post insert), or as some other query like a sequence (pre insert).
30
 *
31
 * @author Jeff Butler
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) {
1✔
40
        this.column = Objects.requireNonNull(column);
1✔
41
        this.isIdentity = isIdentity;
1✔
42

43
        Objects.requireNonNull(configuredSqlStatement);
1✔
44
        this.runtimeSqlStatement = DatabaseDialects.getDatabaseDialect(configuredSqlStatement)
1✔
45
                .map(DatabaseDialects::getIdentityRetrievalStatement)
1✔
46
                .orElse(configuredSqlStatement);
1✔
47
    }
1✔
48

49
    public String getColumn() {
50
        return column;
1✔
51
    }
52

53
    public boolean isIdentity() {
54
        return isIdentity;
1✔
55
    }
56

57
    public String getRuntimeSqlStatement() {
58
        return runtimeSqlStatement;
1✔
59
    }
60

61
    public String getMyBatis3Order() {
62
        return isIdentity ? "AFTER" : "BEFORE"; //$NON-NLS-1$ //$NON-NLS-2$
1✔
63
    }
64

65
    public void validate(List<String> errors, String tableName) {
66
        if (!stringHasValue(runtimeSqlStatement)) {
1!
NEW
67
            errors.add(getString("ValidationError.7", tableName)); //$NON-NLS-1$
×
68
        }
69
    }
1✔
70

71
    public boolean isJdbcStandard() {
72
        return "JDBC".equals(runtimeSqlStatement); //$NON-NLS-1$
1✔
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc