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

mybatis / generator / 1945

14 Jan 2026 02:23PM UTC coverage: 88.838% (+0.04%) from 88.799%
1945

Pull #1414

github

web-flow
Merge 5eec5583d into 5d3363986
Pull Request #1414: Major Refactoring - Context is now configuration only, Plugins Potentially Impacted

2347 of 3184 branches covered (73.71%)

490 of 582 new or added lines in 133 files covered. (84.19%)

2 existing lines in 1 file now uncovered.

11517 of 12964 relevant lines covered (88.84%)

0.89 hits per line

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

90.7
/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.StringUtility.composeFullyQualifiedTableName;
19
import static org.mybatis.generator.internal.util.messages.Messages.getString;
20

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

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

38
public class IntrospectionEngine {
39
    private final Context context;
40
    private final ProgressCallback progressCallback;
41
    private final List<String> warnings;
42
    private final Set<String> fullyQualifiedTableNames;
43
    private final CommentGenerator commentGenerator;
44

45
    protected IntrospectionEngine(Builder builder) {
1✔
46
        context = Objects.requireNonNull(builder.context);
1✔
47
        progressCallback = Objects.requireNonNull(builder.progressCallback);
1✔
48
        warnings = Objects.requireNonNull(builder.warnings);
1✔
49
        fullyQualifiedTableNames = Objects.requireNonNull(builder.fullyQualifiedTableNames);
1✔
50
        commentGenerator = Objects.requireNonNull(builder.commentGenerator);
1✔
51
    }
1✔
52

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

69
        List<IntrospectedTable> introspectedTables = new ArrayList<>();
1✔
70
        JavaTypeResolver javaTypeResolver = ObjectFactory.createJavaTypeResolver(context, warnings);
1✔
71

72
        try (Connection connection = ConnectionUtility.getConnection(context)) {
1✔
73
            progressCallback.startTask(getString("Progress.0")); //$NON-NLS-1$
1✔
74

75
            DatabaseIntrospector databaseIntrospector = new DatabaseIntrospector(
1✔
76
                    context, connection.getMetaData(), javaTypeResolver, warnings, commentGenerator);
1✔
77

78
            // TODO - awkward toList here
79
            for (TableConfiguration tc : context.tableConfigurations().toList()) {
1✔
80
                String tableName = composeFullyQualifiedTableName(tc.getCatalog(), tc
1✔
81
                                .getSchema(), tc.getTableName(), '.');
1✔
82

83
                if (isTableExcluded(tableName)) {
1!
NEW
84
                    continue;
×
85
                }
86

87
                if (!tc.areAnyStatementsEnabled()) {
1!
NEW
88
                    warnings.add(getString("Warning.0", tableName)); //$NON-NLS-1$
×
NEW
89
                    continue;
×
90
                }
91

92
                progressCallback.startTask(getString("Progress.1", tableName)); //$NON-NLS-1$
1✔
93
                List<IntrospectedTable> tables = databaseIntrospector.introspectTables(tc);
1✔
94
                introspectedTables.addAll(tables);
1✔
95

96
                progressCallback.checkCancel();
1✔
97
            }
1✔
98
        }
99

100
        return introspectedTables;
1✔
101
    }
102

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

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

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

115
    public static class Builder {
1✔
116
        private @Nullable Context context;
117
        private @Nullable ProgressCallback progressCallback;
118
        private @Nullable List<String> warnings;
119
        private @Nullable Set<String> fullyQualifiedTableNames;
120
        private @Nullable CommentGenerator commentGenerator;
121

122
        public Builder withContext(Context context) {
123
            this.context = context;
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 Builder withCommentGenerator(CommentGenerator commentGenerator) {
157
            this.commentGenerator = commentGenerator;
1✔
158
            return this;
1✔
159
        }
160

161
        public IntrospectionEngine build() {
162
            return new IntrospectionEngine(this);
1✔
163
        }
164
    }
165
}
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