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

mybatis / generator / 2202

05 May 2026 07:27PM UTC coverage: 91.746% (+0.04%) from 91.703%
2202

push

github

web-flow
Merge pull request #1508 from mybatis/renovate/com.github.javaparser-javaparser-core-3.x

Update dependency com.github.javaparser:javaparser-core to v3.28.1

2454 of 3154 branches covered (77.81%)

12038 of 13121 relevant lines covered (91.75%)

0.92 hits per line

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

61.43
/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/MyBatisGenerator.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.api;
17

18
import static org.mybatis.generator.internal.util.ClassloaderUtility.getCustomClassloader;
19
import static org.mybatis.generator.internal.util.StringUtility.mapStringValueOrElseGet;
20
import static org.mybatis.generator.internal.util.messages.Messages.getString;
21

22
import java.io.BufferedWriter;
23
import java.io.File;
24
import java.io.IOException;
25
import java.io.OutputStream;
26
import java.io.OutputStreamWriter;
27
import java.nio.charset.Charset;
28
import java.nio.file.Files;
29
import java.nio.file.Path;
30
import java.nio.file.StandardOpenOption;
31
import java.sql.SQLException;
32
import java.util.ArrayList;
33
import java.util.Collection;
34
import java.util.HashSet;
35
import java.util.List;
36
import java.util.Objects;
37
import java.util.Set;
38

39
import org.jspecify.annotations.Nullable;
40
import org.mybatis.generator.codegen.CalculatedContextValues;
41
import org.mybatis.generator.codegen.GenerationEngine;
42
import org.mybatis.generator.codegen.GenerationResults;
43
import org.mybatis.generator.codegen.IntrospectionEngine;
44
import org.mybatis.generator.codegen.RootClassInfo;
45
import org.mybatis.generator.config.Configuration;
46
import org.mybatis.generator.config.Context;
47
import org.mybatis.generator.config.IndentationConfiguration;
48
import org.mybatis.generator.exception.InternalException;
49
import org.mybatis.generator.exception.InvalidConfigurationException;
50
import org.mybatis.generator.exception.MergeException;
51
import org.mybatis.generator.exception.ShellException;
52
import org.mybatis.generator.internal.DefaultShellCallback;
53
import org.mybatis.generator.internal.ObjectFactory;
54
import org.mybatis.generator.merge.java.JavaFileMerger;
55
import org.mybatis.generator.merge.java.JavaMergerFactory;
56
import org.mybatis.generator.merge.xml.XmlFileMergerJaxp;
57

58
/**
59
 * This class is the main interface to MyBatis generator. A typical execution of the tool involves these steps:
60
 * <ol>
61
 * <li>Create a Configuration object. The Configuration can be the result of a parsing the XML configuration file, or it
62
 * can be created solely in Java.</li>
63
 * <li>Create a MyBatisGenerator object</li>
64
 * <li>Call one of the generate() methods</li>
65
 * </ol>
66
 *
67
 * @author Jeff Butler
68
 *
69
 * @see org.mybatis.generator.config.xml.ConfigurationParser
70
 */
71
public class MyBatisGenerator {
72
    private final Configuration configuration;
73
    private final ShellCallback shellCallback;
74
    private final ProgressCallback progressCallback;
75
    private final Set<String> contextIds;
76
    private final Set<String> fullyQualifiedTableNames;
77
    private final JavaFileMerger javaFileMerger;
78
    private final boolean isOverwriteEnabled;
79
    private final boolean isJavaFileMergeEnabled;
80
    private final Indenter defaultIndenter;
81

82
    private final List<GenerationResults> generationResultsList = new ArrayList<>();
1✔
83

84
    private MyBatisGenerator(Builder builder) {
1✔
85
        configuration = Objects.requireNonNull(builder.configuration, getString("RuntimeError.2")); //$NON-NLS-1$
1✔
86
        shellCallback = Objects.requireNonNullElseGet(builder.shellCallback, DefaultShellCallback::new);
1✔
87
        progressCallback = Objects.requireNonNullElseGet(builder.progressCallback, () -> new ProgressCallback() {});
1✔
88
        fullyQualifiedTableNames = builder.fullyQualifiedTableNames;
1✔
89
        contextIds = builder.contextIds;
1✔
90

91
        if (builder.isJavaFileMergeEnabled) {
1!
92
            isJavaFileMergeEnabled = true;
×
93
            javaFileMerger = JavaMergerFactory.getMerger(JavaMergerFactory.PrinterConfiguration.LEXICAL_PRESERVING);
×
94
        } else {
95
            isJavaFileMergeEnabled = false;
1✔
96
            javaFileMerger = (newContent, existingContent) -> newContent;
1✔
97
        }
98

99
        isOverwriteEnabled = builder.isOverwriteEnabled;
1✔
100
        defaultIndenter = Objects.requireNonNullElseGet(builder.indenter, Indenter::defaultIndenter);
1✔
101
    }
1✔
102

103
    /**
104
     * This is one of the main methods for generating code. This method is long-running, but progress can be provided
105
     * and the method can be canceled through the ProgressCallback interface. This method will not write results to
106
     * the disk. The generated objects can be retrieved from the getGeneratedJavaFiles(), getGeneratedKotlinFiles(),
107
     * getGeneratedXmlFiles(), and getGeneratedGenericFiles() methods.
108
     *
109
     * @return any warnings created during the generation process
110
     * @throws SQLException
111
     *             the SQL exception
112
     * @throws InterruptedException
113
     *             if the method is canceled through the ProgressCallback
114
     * @throws InvalidConfigurationException
115
     *             if the specified configuration is invalid
116
     */
117
    public List<String> generateOnly() throws SQLException, InterruptedException,
118
            InvalidConfigurationException {
119
        List<String> warnings = new ArrayList<>();
1✔
120
        generateFiles(warnings);
1✔
121
        progressCallback.done();
1✔
122
        return warnings;
1✔
123
    }
124

125
    /**
126
     * This is one of the main methods for generating code. This method is long-running, but progress can be provided
127
     * and the method can be canceled through the ProgressCallback interface. This method will write results to
128
     * the disk.
129
     *
130
     * @return any warnings created during the generation process
131
     * @throws SQLException
132
     *             the SQL exception
133
     * @throws IOException
134
     *             Signals that an I/O exception has occurred.
135
     * @throws InterruptedException
136
     *             if the method is canceled through the ProgressCallback
137
     * @throws InvalidConfigurationException
138
     *             if the specified configuration is invalid
139
     */
140
    public List<String> generateAndWrite() throws SQLException, IOException, InterruptedException,
141
            InvalidConfigurationException {
142
        List<String> warnings = new ArrayList<>();
1✔
143
        generateFiles(warnings);
1✔
144
        writeGeneratedFiles(warnings);
1✔
145
        progressCallback.done();
1✔
146
        return warnings;
1✔
147
    }
148

149
    private void generateFiles(List<String> warnings) throws SQLException, InterruptedException,
150
            InvalidConfigurationException {
151
        configuration.validate();
1✔
152
        generationResultsList.clear();
1✔
153
        ObjectFactory.reset();
1✔
154
        RootClassInfo.reset();
1✔
155

156
        Indenter globalIndenter = configuration.getIndentationConfiguration()
1✔
157
                .map(IndentationConfiguration::getIndenter)
1✔
158
                .orElse(defaultIndenter);
1✔
159

160
        setupCustomClassloader();
1✔
161
        List<Context> contextsToRun = calculateContextsToRun();
1✔
162
        List<CalculatedContextValues> contextValuesList = calculateContextValues(contextsToRun, globalIndenter,
1✔
163
                warnings);
164
        List<ContextValuesAndTables> contextValuesAndTablesList = runAllIntrospections(contextValuesList, warnings);
1✔
165
        List<GenerationEngine> generationEngines = createGenerationEngines(contextValuesAndTablesList, warnings);
1✔
166
        runGenerationEngines(generationEngines);
1✔
167
    }
1✔
168

169
    private void setupCustomClassloader() {
170
        if (!configuration.getClassPathEntries().isEmpty()) {
1!
171
            ClassLoader classLoader = getCustomClassloader(configuration.getClassPathEntries());
×
172
            ObjectFactory.addExternalClassLoader(classLoader);
×
173
        }
174
    }
1✔
175

176
    private List<Context> calculateContextsToRun() {
177
        List<Context> contextsToRun;
178
        if (fullyQualifiedTableNames.isEmpty()) {
1!
179
            contextsToRun = configuration.getContexts();
1✔
180
        } else {
181
            contextsToRun = configuration.getContexts().stream()
×
182
                    .filter(c -> contextIds.contains(c.getId()))
×
183
                    .toList();
×
184
        }
185

186
        return contextsToRun;
1✔
187
    }
188

189
    private List<CalculatedContextValues> calculateContextValues(List<Context> contextsToRun, Indenter globalIndenter,
190
                                                                 List<String> warnings) {
191
        return contextsToRun.stream()
1✔
192
                .map(c -> createContextValues(c, globalIndenter, warnings))
1✔
193
                .toList();
1✔
194
    }
195

196
    private CalculatedContextValues createContextValues(Context context, Indenter globalIndenter,
197
                                                        List<String> warnings) {
198
        return new CalculatedContextValues.Builder()
1✔
199
                .withContext(context)
1✔
200
                .withWarnings(warnings)
1✔
201
                .withIndenter(context.getIndentationConfiguration()
1✔
202
                        .map(IndentationConfiguration::getIndenter)
1✔
203
                        .orElse(globalIndenter))
1✔
204
                .build();
1✔
205
    }
206

207
    private List<ContextValuesAndTables> runAllIntrospections(List<CalculatedContextValues> contextValuesList,
208
                                                              List<String> warnings)
209
            throws SQLException, InterruptedException {
210
        int totalSteps = contextValuesList.stream()
1✔
211
                .map(CalculatedContextValues::context)
1✔
212
                .mapToInt(Context::getIntrospectionSteps)
1✔
213
                .sum();
1✔
214
        progressCallback.introspectionStarted(totalSteps);
1✔
215

216
        List<ContextValuesAndTables> contextValuesAndTablesList = new ArrayList<>();
1✔
217
        for (CalculatedContextValues contextValues : contextValuesList) {
1✔
218
            contextValuesAndTablesList.add(new ContextValuesAndTables(contextValues,
1✔
219
                    runContextIntrospection(fullyQualifiedTableNames, contextValues, warnings)));
1✔
220
        }
1✔
221

222
        return contextValuesAndTablesList;
1✔
223
    }
224

225
    private List<IntrospectedTable> runContextIntrospection(Set<String> fullyQualifiedTableNames,
226
                                                            CalculatedContextValues contextValues,
227
                                                            List<String> warnings)
228
            throws SQLException, InterruptedException {
229
        return new IntrospectionEngine.Builder()
1✔
230
                .withContextValues(contextValues)
1✔
231
                .withFullyQualifiedTableNames(fullyQualifiedTableNames)
1✔
232
                .withWarnings(warnings)
1✔
233
                .withProgressCallback(progressCallback)
1✔
234
                .build()
1✔
235
                .introspectTables();
1✔
236
    }
237

238
    private List<GenerationEngine> createGenerationEngines(List<ContextValuesAndTables> contextValuesAndTablesListList,
239
                                                           List<String> warnings) {
240
        return contextValuesAndTablesListList.stream()
1✔
241
                .map(c -> createGenerationEngine(c, warnings))
1✔
242
                .toList();
1✔
243
    }
244

245
    private GenerationEngine createGenerationEngine(ContextValuesAndTables contextValuesAndTables,
246
                                                    List<String> warnings) {
247
        return new GenerationEngine.Builder()
1✔
248
                .withContextValues(contextValuesAndTables.contextValues())
1✔
249
                .withProgressCallback(progressCallback)
1✔
250
                .withWarnings(warnings)
1✔
251
                .withIntrospectedTables(contextValuesAndTables.introspectedTables())
1✔
252
                .build();
1✔
253
    }
254

255
    private void runGenerationEngines(List<GenerationEngine> generationEngines) throws InterruptedException {
256
        // calculate the number of steps
257
        int totalSteps = generationEngines.stream().mapToInt(GenerationEngine::getGenerationSteps).sum();
1✔
258
        progressCallback.generationStarted(totalSteps);
1✔
259

260
        // now run the generators
261
        for (GenerationEngine generationEngine: generationEngines) {
1✔
262
            var generationResults = generationEngine.generate();
1✔
263
            generationResultsList.add(generationResults);
1✔
264
        }
1✔
265
    }
1✔
266

267
    private void writeGeneratedFiles(List<String> warnings) throws IOException, InterruptedException {
268
        Set<String> projects = new HashSet<>();
1✔
269
        int totalSteps = generationResultsList.stream().mapToInt(GenerationResults::getNumberOfGeneratedFiles).sum();
1✔
270
        progressCallback.saveStarted(totalSteps);
1✔
271

272
        for (GenerationResults generationResults : generationResultsList) {
1✔
273
            for (GeneratedXmlFile gxf : generationResults.generatedXmlFiles()) {
1!
274
                projects.add(gxf.getTargetProject());
×
275
                writeGeneratedXmlFile(gxf, generationResults.xmlFormatter(), warnings);
×
276
            }
×
277

278
            for (GeneratedJavaFile gjf : generationResults.generatedJavaFiles()) {
1!
279
                projects.add(gjf.getTargetProject());
×
280
                writeGeneratedJavaFile(gjf, generationResults.javaFormatter(), generationResults.javaFileEncoding(),
×
281
                        warnings);
282
            }
×
283

284
            for (GeneratedKotlinFile gkf : generationResults.generatedKotlinFiles()) {
1!
285
                projects.add(gkf.getTargetProject());
×
286
                writeGeneratedKotlinFile(gkf, generationResults.kotlinFormatter(),
×
287
                        generationResults.kotlinFileEncoding(), warnings);
×
288
            }
×
289

290
            for (GenericGeneratedFile gf : generationResults.generatedGenericFiles()) {
1!
291
                projects.add(gf.getTargetProject());
×
292
                writeGenericGeneratedFile(gf, warnings);
×
293
            }
×
294
        }
1✔
295

296
        for (String project : projects) {
1!
297
            shellCallback.refreshProject(project);
×
298
        }
×
299
    }
1✔
300

301
    private void writeGeneratedJavaFile(GeneratedJavaFile gf, JavaFormatter javaFormatter,
302
                                        @Nullable String javaFileEncoding, List<String> warnings)
303
            throws InterruptedException, IOException {
304
        String source = javaFormatter.getFormattedContent(gf.getCompilationUnit());
×
305
        writeFile(source, javaFileEncoding, gf, warnings, isJavaFileMergeEnabled,
×
306
                (newContent, existingContent) -> javaFileMerger.getMergedSource(newContent, existingContent,
×
307
                        javaFileEncoding));
308
    }
×
309

310
    private void writeGeneratedKotlinFile(GeneratedKotlinFile gf, KotlinFormatter kotlinFormatter,
311
                                          @Nullable String kotlinFileEncoding, List<String> warnings)
312
            throws InterruptedException, IOException {
313
        String source = kotlinFormatter.getFormattedContent(gf.getKotlinFile());
×
314
        writeFile(source, kotlinFileEncoding, gf, warnings, false, Merger.noMerge());
×
315
    }
×
316

317
    private void writeGenericGeneratedFile(GenericGeneratedFile gf, List<String> warnings)
318
            throws InterruptedException, IOException {
319
        String source = gf.getFormattedContent();
×
320
        writeFile(source, gf.getFileEncoding().orElse(null), gf, warnings, false, Merger.noMerge());
×
321
    }
×
322

323
    private void writeGeneratedXmlFile(GeneratedXmlFile gf, XmlFormatter xmlFormatter, List<String> warnings)
324
            throws InterruptedException, IOException {
325
        String source = xmlFormatter.getFormattedContent(gf.getDocument());
×
326
        writeFile(source, "UTF-8", gf, warnings, true, XmlFileMergerJaxp::getMergedSource); //$NON-NLS-1$
×
327
    }
×
328

329
    private void writeFile(String content, @Nullable String encoding, GeneratedFile gf, List<String> warnings,
330
                           boolean mergeEnabled, Merger merger)
331
            throws InterruptedException, IOException {
332
        try {
333
            File directory = shellCallback.getDirectory(gf.getTargetProject(), gf.getTargetPackage());
×
334
            Path targetFile = directory.toPath().resolve(gf.getFileName());
×
335
            if (Files.exists(targetFile)) {
×
336
                if (mergeEnabled && gf.isMergeable()) {
×
337
                    content = merger.apply(content, targetFile.toFile());
×
338
                } else if (isOverwriteEnabled) {
×
339
                    warnings.add(getString("Warning.11", targetFile.toFile().getAbsolutePath())); //$NON-NLS-1$
×
340
                } else {
341
                    targetFile = getUniqueFileName(directory, gf.getFileName());
×
342
                    warnings.add(getString("Warning.2", targetFile.toFile().getAbsolutePath())); //$NON-NLS-1$
×
343
                }
344
            }
345

346
            progressCallback.checkCancel();
×
347
            progressCallback.startTask(getString("Progress.15", targetFile.toString())); //$NON-NLS-1$
×
348
            writeFile(targetFile.toFile(), content, encoding);
×
349
        } catch (ShellException e) {
×
350
            warnings.add(e.getMessage());
×
351
        } catch (MergeException e) {
×
352
            warnings.add(e.getMessage());
×
353
            warnings.addAll(e.getExtraMessages());
×
354
        }
×
355
    }
×
356

357
    /**
358
     * Writes, or overwrites, the contents of the specified file.
359
     *
360
     * @param file
361
     *            the file
362
     * @param content
363
     *            the content
364
     * @param fileEncoding
365
     *            the file encoding
366
     * @throws IOException
367
     *             Signals that an I/O exception has occurred.
368
     */
369
    private void writeFile(File file, String content, @Nullable String fileEncoding) throws IOException {
370
        Charset cs = mapStringValueOrElseGet(fileEncoding, Charset::forName, Charset::defaultCharset);
×
371
        try (OutputStream outputStream = Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE,
×
372
                StandardOpenOption.TRUNCATE_EXISTING)) {
373
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, cs)) {
×
374
                try (BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
×
375
                    bufferedWriter.write(content);
×
376
                }
377
            }
378
        }
379
    }
×
380

381
    /**
382
     * Gets the unique file name.
383
     *
384
     * @param directory
385
     *            the directory
386
     * @param fileName
387
     *            the file name
388
     * @return the unique file name
389
     */
390
    private Path getUniqueFileName(File directory, String fileName) {
391
        Path answer = null;
×
392

393
        // try up to 1000 times to generate a unique file name
394
        StringBuilder sb = new StringBuilder();
×
395
        for (int i = 1; i < 1000; i++) {
×
396
            sb.setLength(0);
×
397
            sb.append(fileName);
×
398
            sb.append('.');
×
399
            sb.append(i);
×
400

401
            Path testFile = directory.toPath().resolve(sb.toString());
×
402
            if (Files.notExists(testFile)) {
×
403
                answer = testFile;
×
404
                break;
×
405
            }
406
        }
407

408
        if (answer == null) {
×
409
            throw new InternalException(getString("RuntimeError.3", directory.getAbsolutePath())); //$NON-NLS-1$
×
410
        }
411

412
        return answer;
×
413
    }
414

415
    /**
416
     * Returns the list of generated Java files after a call to one of the generate methods.
417
     * This is useful if you prefer to process the generated files yourself and do not want
418
     * the generator to write them to disk.
419
     *
420
     * @return the list of generated Java files
421
     */
422
    public List<GeneratedJavaFile> getGeneratedJavaFiles() {
423
        return generationResultsList.stream()
1✔
424
                .map(GenerationResults::generatedJavaFiles)
1✔
425
                .flatMap(Collection::stream)
1✔
426
                .toList();
1✔
427
    }
428

429
    /**
430
     * Returns the list of generated Kotlin files after a call to one of the generate methods.
431
     * This is useful if you prefer to process the generated files yourself and do not want
432
     * the generator to write them to disk.
433
     *
434
     * @return the list of generated Kotlin files
435
     */
436
    public List<GeneratedKotlinFile> getGeneratedKotlinFiles() {
437
        return generationResultsList.stream()
1✔
438
                .map(GenerationResults::generatedKotlinFiles)
1✔
439
                .flatMap(Collection::stream)
1✔
440
                .toList();
1✔
441
    }
442

443
    /**
444
     * Returns the list of generated XML files after a call to one of the generate methods.
445
     * This is useful if you prefer to process the generated files yourself and do not want
446
     * the generator to write them to disk.
447
     *
448
     * @return the list of generated XML files
449
     */
450
    public List<GeneratedXmlFile> getGeneratedXmlFiles() {
451
        return generationResultsList.stream()
1✔
452
                .map(GenerationResults::generatedXmlFiles)
1✔
453
                .flatMap(Collection::stream)
1✔
454
                .toList();
1✔
455
    }
456

457
    /**
458
     * Returns the list of generated generic files after a call to one of the generate methods.
459
     * This is useful if you prefer to process the generated files yourself and do not want
460
     * the generator to write them to disk.
461
     *
462
     * <p>The list will be empty unless you have used a plugin that generates generic files
463
     * or are using a custom runtime.
464
     *
465
     * @return the list of generated generic files
466
     */
467
    public List<GenericGeneratedFile> getGeneratedGenericFiles() {
468
        return generationResultsList.stream()
×
469
                .map(GenerationResults::generatedGenericFiles)
×
470
                .flatMap(Collection::stream)
×
471
                .toList();
×
472
    }
473

474
    private record ContextValuesAndTables(CalculatedContextValues contextValues,
1✔
475
                                          List<IntrospectedTable> introspectedTables) { }
476

477
    @FunctionalInterface
478
    private interface Merger {
479
        String apply(String newContent, File existingContent) throws MergeException;
480

481
        static Merger noMerge() {
482
            return (newContent, existingContent) -> newContent;
×
483
        }
484
    }
485

486
    public static class Builder {
1✔
487
        private @Nullable Configuration configuration;
488
        private @Nullable ShellCallback shellCallback;
489
        private @Nullable ProgressCallback progressCallback;
490
        private final Set<String> contextIds = new HashSet<>();
1✔
491
        private final Set<String> fullyQualifiedTableNames = new HashSet<>();
1✔
492
        private boolean isOverwriteEnabled = false;
1✔
493
        private boolean isJavaFileMergeEnabled = false;
1✔
494
        private @Nullable Indenter indenter;
495

496
        public Builder withConfiguration(Configuration configuration) {
497
            this.configuration = configuration;
1✔
498
            return this;
1✔
499
        }
500

501
        public Builder withShellCallback(ShellCallback shellCallback) {
502
            this.shellCallback = shellCallback;
1✔
503
            return this;
1✔
504
        }
505

506
        public Builder withProgressCallback(@Nullable ProgressCallback progressCallback) {
507
            this.progressCallback = progressCallback;
1✔
508
            return this;
1✔
509
        }
510

511
        /**
512
         * Set of context IDs to use in generation. Only the contexts with an id specified in this set will run.
513
         * If the set is empty, then all contexts are run.
514
         *
515
         * @param contextIds
516
         *            a set of contextIds to use in code generation
517
         *
518
         * @return this builder
519
         */
520
        public Builder withContextIds(Set<String> contextIds) {
521
            this.contextIds.addAll(contextIds);
1✔
522
            return this;
1✔
523
        }
524

525
        /**
526
         *  Set of table names to generate. The elements of the set must be Strings that exactly match what's
527
         *  specified in the configuration. For example, if a table name = "foo" and schema = "bar", then the fully
528
         *  qualified table name is "foo.bar". If the Set is empty, then all tables in the configuration
529
         *  will be used for code generation.
530
         *
531
         * @param fullyQualifiedTableNames
532
         *            a set of table names to use in code generation
533
         *
534
         * @return this builder
535
         */
536
        public Builder withFullyQualifiedTableNames(Set<String> fullyQualifiedTableNames) {
537
            this.fullyQualifiedTableNames.addAll(fullyQualifiedTableNames);
1✔
538
            return this;
1✔
539
        }
540

541
        /**
542
         * If true, then newly generated files will overwrite existing files if there is a collision.
543
         * If false, then newly generated files will be written with a unique name when there is a collision.
544
         *
545
         * <p>The default is <code>false</code></p>
546
         *
547
         * @param overwriteEnabled where newly generated files should overwrite existing files if there is a collision
548
         * @return this builder
549
         */
550
        public Builder withOverwriteEnabled(boolean overwriteEnabled) {
551
            this.isOverwriteEnabled = overwriteEnabled;
1✔
552
            return this;
1✔
553
        }
554

555
        /**
556
         * If true, then newly generated Java files will be merged if they collide with existing files.
557
         * If false, then the {@link #withOverwriteEnabled(boolean)} value governs what happens on a collision.
558
         *
559
         * <p>The default is <code>false</code></p>
560
         *
561
         * @param javaFileMergeEnabled where the Java file merger support should be enabled
562
         * @return this builder
563
         */
564
        public Builder withJavaFileMergeEnabled(boolean javaFileMergeEnabled) {
565
            this.isJavaFileMergeEnabled = javaFileMergeEnabled;
1✔
566
            return this;
1✔
567
        }
568

569
        /**
570
         * Specify an indenter to use if no indenters are configured in the configuration.
571
         * If not specified, then the library will use the default indenter.
572
         *
573
         * @param indenter an indenter to use if no indenters are configured. This indenter will not override
574
         *                 indenters specified in a configuration.
575
         * @return this builder
576
         */
577
        public Builder withIndenter(Indenter indenter) {
578
            this.indenter = indenter;
×
579
            return this;
×
580
        }
581

582
        public MyBatisGenerator build() {
583
            return new MyBatisGenerator(this);
1✔
584
        }
585
    }
586
}
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