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

mybatis / generator / 2136

02 Apr 2026 07:17PM UTC coverage: 91.775% (+1.4%) from 90.382%
2136

Pull #1485

github

web-flow
Merge 516685a9a into 18f1f002d
Pull Request #1485: Code Cleanup and Coverage

2425 of 3124 branches covered (77.62%)

191 of 235 new or added lines in 54 files covered. (81.28%)

7 existing lines in 4 files now uncovered.

11884 of 12949 relevant lines covered (91.78%)

0.92 hits per line

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

88.37
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/codegen/IntrospectionEngine.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.codegen;
17

18
import static org.mybatis.generator.internal.util.messages.Messages.getString;
19

20
import java.sql.Connection;
21
import java.sql.SQLException;
22
import java.util.ArrayList;
23
import java.util.List;
24
import java.util.Objects;
25
import java.util.Set;
26

27
import org.jspecify.annotations.Nullable;
28
import org.mybatis.generator.api.IntrospectedTable;
29
import org.mybatis.generator.api.JavaTypeResolver;
30
import org.mybatis.generator.api.ProgressCallback;
31
import org.mybatis.generator.config.TableConfiguration;
32
import org.mybatis.generator.internal.ObjectFactory;
33
import org.mybatis.generator.internal.db.DatabaseIntrospector;
34

35
public class IntrospectionEngine {
36
    private final CalculatedContextValues contextValues;
37
    private final ProgressCallback progressCallback;
38
    private final List<String> warnings;
39
    private final Set<String> fullyQualifiedTableNames;
40

41
    protected IntrospectionEngine(Builder builder) {
1✔
42
        contextValues = Objects.requireNonNull(builder.contextValues);
1✔
43
        progressCallback = Objects.requireNonNull(builder.progressCallback);
1✔
44
        warnings = Objects.requireNonNull(builder.warnings);
1✔
45
        fullyQualifiedTableNames = Objects.requireNonNull(builder.fullyQualifiedTableNames);
1✔
46
    }
1✔
47

48
    /**
49
     * Introspect tables based on the configuration specified in the
50
     * constructor. This method is long-running.
51
     *
52
     * @return a list containing the results of table introspection. The list will be empty
53
     *     if this method is called before introspectTables(), or if no tables are found that
54
     *     match the configuration
55
     *
56
     * @throws java.sql.SQLException
57
     *             if some error arises while introspecting the specified
58
     *             database tables.
59
     * @throws InterruptedException
60
     *             if the progress callback reports a cancel
61
     */
62
    public List<IntrospectedTable> introspectTables()
63
            throws SQLException, InterruptedException {
64

65
        List<IntrospectedTable> introspectedTables = new ArrayList<>();
1✔
66
        JavaTypeResolver javaTypeResolver = ObjectFactory.createJavaTypeResolver(contextValues.context(), warnings);
1✔
67

68
        try (Connection connection = ConnectionUtility.getConnection(contextValues.context())) {
1✔
69
            progressCallback.startTask(getString("Progress.0")); //$NON-NLS-1$
1✔
70

71
            DatabaseIntrospector databaseIntrospector = new DatabaseIntrospector(
1✔
72
                    contextValues.context(), connection.getMetaData(), javaTypeResolver);
1✔
73

74
            for (TableConfiguration tc : contextValues.context().tableConfigurations()) {
1✔
75
                if (!shouldIntrospect(tc)) {
1!
UNCOV
76
                    continue;
×
77
                }
78

79
                progressCallback.startTask(getString("Progress.1", tc.getFullyQualifiedName())); //$NON-NLS-1$
1✔
80
                List<IntrospectedTable> tables = databaseIntrospector
1✔
81
                        .introspectTables(tc, contextValues.knownRuntime(), contextValues.pluginAggregator());
1✔
82
                introspectedTables.addAll(tables);
1✔
83

84
                progressCallback.checkCancel();
1✔
85
            }
1✔
86

87
            warnings.addAll(databaseIntrospector.getWarnings());
1✔
88
        }
89

90
        return introspectedTables;
1✔
91
    }
92

93
    private boolean shouldIntrospect(TableConfiguration tc) {
94
        if (isTableExcluded(tc.getFullyQualifiedName())) {
1!
NEW
95
            return false;
×
96
        }
97

98
        if (contextValues.knownRuntime().isLegacyMyBatis3Based() && !tc.areAnyStatementsEnabled()) {
1!
NEW
99
            warnings.add(getString("Warning.0", tc.getFullyQualifiedName())); //$NON-NLS-1$
×
NEW
100
            return false;
×
101
        }
102

103
        return true;
1✔
104
    }
105

106
    private boolean isTableExcluded(String tableName) {
107
        return !isTableIncluded(tableName);
1!
108
    }
109

110
    private boolean isTableIncluded(String tableName) {
111
        if (fullyQualifiedTableNames.isEmpty()) {
1!
112
            return true;
1✔
113
        }
114

115
        return fullyQualifiedTableNames.contains(tableName);
×
116
    }
117

118
    public static class Builder {
1✔
119
        private @Nullable CalculatedContextValues contextValues;
120
        private @Nullable ProgressCallback progressCallback;
121
        private @Nullable List<String> warnings;
122
        private @Nullable Set<String> fullyQualifiedTableNames;
123

124
        public Builder withContextValues(CalculatedContextValues contextValues) {
125
            this.contextValues = contextValues;
1✔
126
            return this;
1✔
127
        }
128

129
        public Builder withProgressCallback(ProgressCallback progressCallback) {
130
            this.progressCallback = progressCallback;
1✔
131
            return this;
1✔
132
        }
133

134
        public Builder withWarnings(List<String> warnings) {
135
            this.warnings = warnings;
1✔
136
            return this;
1✔
137
        }
138

139
        /**
140
         * Sets a Set of table names for introspection.
141
         *
142
         * @param fullyQualifiedTableNames
143
         *            a set of table names to introspect. The elements of the set must
144
         *            be Strings that exactly match what's specified in the
145
         *            configuration. For example, if a table name is "foo" and the schema is
146
         *            "bar", then the fully qualified table name is "foo.bar". If
147
         *            the Set is empty, then all tables in the configuration
148
         *            will be used for code generation.
149
         *
150
         *
151
         * @return this builder
152
         */
153
        public Builder withFullyQualifiedTableNames(Set<String> fullyQualifiedTableNames) {
154
            this.fullyQualifiedTableNames = fullyQualifiedTableNames;
1✔
155
            return this;
1✔
156
        }
157

158
        public IntrospectionEngine build() {
159
            return new IntrospectionEngine(this);
1✔
160
        }
161
    }
162
}
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