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

mybatis / generator / 2135

02 Apr 2026 05:50PM UTC coverage: 91.765% (+1.4%) from 90.382%
2135

Pull #1485

github

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

2425 of 3126 branches covered (77.58%)

134 of 172 new or added lines in 28 files covered. (77.91%)

7 existing lines in 4 files now uncovered.

11879 of 12945 relevant lines covered (91.77%)

0.92 hits per line

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

88.1
/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, warnings);
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

88
        return introspectedTables;
1✔
89
    }
90

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

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

101
        return true;
1✔
102
    }
103

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

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

113
        return fullyQualifiedTableNames.contains(tableName);
×
114
    }
115

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

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

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

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

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

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