• 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

61.62
/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.exception.InternalException;
48
import org.mybatis.generator.exception.InvalidConfigurationException;
49
import org.mybatis.generator.exception.ShellException;
50
import org.mybatis.generator.internal.DefaultShellCallback;
51
import org.mybatis.generator.internal.ObjectFactory;
52
import org.mybatis.generator.merge.java.JavaFileMerger;
53
import org.mybatis.generator.merge.java.JavaMergerFactory;
54
import org.mybatis.generator.merge.xml.XmlFileMergerJaxp;
55

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

79
    private final List<GenerationResults> generationResultsList = new ArrayList<>();
1✔
80

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

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

96
        isOverwriteEnabled = builder.isOverwriteEnabled;
1✔
97
    }
1✔
98

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

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

144
    private void generateFiles(List<String> warnings) throws SQLException, InterruptedException,
145
            InvalidConfigurationException {
146
        configuration.validate();
1✔
147
        generationResultsList.clear();
1✔
148
        ObjectFactory.reset();
1✔
149
        RootClassInfo.reset();
1✔
150

151
        setupCustomClassloader();
1✔
152
        List<Context> contextsToRun = calculateContextsToRun();
1✔
153
        List<CalculatedContextValues> contextValuesList = calculateContextValues(contextsToRun, warnings);
1✔
154
        List<ContextValuesAndTables> contextValuesAndTablesList = runAllIntrospections(contextValuesList, warnings);
1✔
155
        List<GenerationEngine> generationEngines = createGenerationEngines(contextValuesAndTablesList, warnings);
1✔
156
        runGenerationEngines(generationEngines);
1✔
157
    }
1✔
158

159
    private void setupCustomClassloader() {
160
        if (!configuration.getClassPathEntries().isEmpty()) {
1!
161
            ClassLoader classLoader = getCustomClassloader(configuration.getClassPathEntries());
×
162
            ObjectFactory.addExternalClassLoader(classLoader);
×
163
        }
164
    }
1✔
165

166
    private List<Context> calculateContextsToRun() {
167
        List<Context> contextsToRun;
168
        if (fullyQualifiedTableNames.isEmpty()) {
1!
169
            contextsToRun = configuration.getContexts();
1✔
170
        } else {
171
            contextsToRun = configuration.getContexts().stream()
×
172
                    .filter(c -> contextIds.contains(c.getId()))
×
173
                    .toList();
×
174
        }
175

176
        return contextsToRun;
1✔
177
    }
178

179
    private List<CalculatedContextValues> calculateContextValues(List<Context> contextsToRun, List<String> warnings) {
180
        return contextsToRun.stream()
1✔
181
                .map(c -> createContextValues(c, warnings))
1✔
182
                .toList();
1✔
183
    }
184

185
    private CalculatedContextValues createContextValues(Context context, List<String> warnings) {
186
        return new CalculatedContextValues.Builder()
1✔
187
                .withContext(context)
1✔
188
                .withWarnings(warnings)
1✔
189
                .build();
1✔
190
    }
191

192
    private List<ContextValuesAndTables> runAllIntrospections(List<CalculatedContextValues> contextValuesList,
193
                                                              List<String> warnings)
194
            throws SQLException, InterruptedException {
195
        int totalSteps = contextValuesList.stream()
1✔
196
                .map(CalculatedContextValues::context)
1✔
197
                .mapToInt(Context::getIntrospectionSteps)
1✔
198
                .sum();
1✔
199
        progressCallback.introspectionStarted(totalSteps);
1✔
200

201
        List<ContextValuesAndTables> contextValuesAndTablesList = new ArrayList<>();
1✔
202
        for (CalculatedContextValues contextValues : contextValuesList) {
1✔
203
            contextValuesAndTablesList.add(new ContextValuesAndTables(contextValues,
1✔
204
                    runContextIntrospection(fullyQualifiedTableNames, contextValues, warnings)));
1✔
205
        }
1✔
206

207
        return contextValuesAndTablesList;
1✔
208
    }
209

210
    private List<IntrospectedTable> runContextIntrospection(Set<String> fullyQualifiedTableNames,
211
                                                            CalculatedContextValues contextValues,
212
                                                            List<String> warnings)
213
            throws SQLException, InterruptedException {
214
        return new IntrospectionEngine.Builder()
1✔
215
                .withContextValues(contextValues)
1✔
216
                .withFullyQualifiedTableNames(fullyQualifiedTableNames)
1✔
217
                .withWarnings(warnings)
1✔
218
                .withProgressCallback(progressCallback)
1✔
219
                .build()
1✔
220
                .introspectTables();
1✔
221
    }
222

223
    private List<GenerationEngine> createGenerationEngines(List<ContextValuesAndTables> contextValuesAndTablesListList,
224
                                                           List<String> warnings) {
225
        return contextValuesAndTablesListList.stream()
1✔
226
                .map(c -> createGenerationEngine(c, warnings))
1✔
227
                .toList();
1✔
228
    }
229

230
    private GenerationEngine createGenerationEngine(ContextValuesAndTables contextValuesAndTables,
231
                                                    List<String> warnings) {
232
        return new GenerationEngine.Builder()
1✔
233
                .withContextValues(contextValuesAndTables.contextValues())
1✔
234
                .withProgressCallback(progressCallback)
1✔
235
                .withWarnings(warnings)
1✔
236
                .withIntrospectedTables(contextValuesAndTables.introspectedTables())
1✔
237
                .build();
1✔
238
    }
239

240
    private void runGenerationEngines(List<GenerationEngine> generationEngines) throws InterruptedException {
241
        // calculate the number of steps
242
        int totalSteps = generationEngines.stream().mapToInt(GenerationEngine::getGenerationSteps).sum();
1✔
243
        progressCallback.generationStarted(totalSteps);
1✔
244

245
        // now run the generators
246
        for (GenerationEngine generationEngine: generationEngines) {
1✔
247
            var generationResults = generationEngine.generate();
1✔
248
            generationResultsList.add(generationResults);
1✔
249
        }
1✔
250
    }
1✔
251

252
    private void writeGeneratedFiles(List<String> warnings) throws IOException, InterruptedException {
253
        Set<String> projects = new HashSet<>();
1✔
254
        int totalSteps = generationResultsList.stream().mapToInt(GenerationResults::getNumberOfGeneratedFiles).sum();
1✔
255
        progressCallback.saveStarted(totalSteps);
1✔
256

257
        for (GenerationResults generationResults : generationResultsList) {
1✔
258
            for (GeneratedXmlFile gxf : generationResults.generatedXmlFiles()) {
1!
259
                projects.add(gxf.getTargetProject());
×
260
                writeGeneratedXmlFile(gxf, generationResults.xmlFormatter(), warnings);
×
261
            }
×
262

263
            for (GeneratedJavaFile gjf : generationResults.generatedJavaFiles()) {
1!
264
                projects.add(gjf.getTargetProject());
×
265
                writeGeneratedJavaFile(gjf, generationResults.javaFormatter(), generationResults.javaFileEncoding(),
×
266
                        warnings);
267
            }
×
268

269
            for (GeneratedKotlinFile gkf : generationResults.generatedKotlinFiles()) {
1!
270
                projects.add(gkf.getTargetProject());
×
271
                writeGeneratedKotlinFile(gkf, generationResults.kotlinFormatter(),
×
272
                        generationResults.kotlinFileEncoding(), warnings);
×
273
            }
×
274

275
            for (GenericGeneratedFile gf : generationResults.generatedGenericFiles()) {
1!
276
                projects.add(gf.getTargetProject());
×
277
                writeGenericGeneratedFile(gf, warnings);
×
278
            }
×
279
        }
1✔
280

281
        for (String project : projects) {
1!
282
            shellCallback.refreshProject(project);
×
283
        }
×
284
    }
1✔
285

286
    private void writeGeneratedJavaFile(GeneratedJavaFile gf, JavaFormatter javaFormatter,
287
                                        @Nullable String javaFileEncoding, List<String> warnings)
288
            throws InterruptedException, IOException {
NEW
289
        String source = javaFormatter.getFormattedContent(gf.getCompilationUnit());
×
NEW
290
        writeFile(source, javaFileEncoding, gf, warnings, isJavaFileMergeEnabled,
×
NEW
291
                (newContent, existingContent) -> javaFileMerger.getMergedSource(newContent, existingContent,
×
292
                        javaFileEncoding));
UNCOV
293
    }
×
294

295
    private void writeGeneratedKotlinFile(GeneratedKotlinFile gf, KotlinFormatter kotlinFormatter,
296
                                          @Nullable String kotlinFileEncoding, List<String> warnings)
297
            throws InterruptedException, IOException {
UNCOV
298
        String source = kotlinFormatter.getFormattedContent(gf.getKotlinFile());
×
NEW
299
        writeFile(source, kotlinFileEncoding, gf, warnings, false, Merger.noMerge());
×
300
    }
×
301

302
    private void writeGenericGeneratedFile(GenericGeneratedFile gf, List<String> warnings)
303
            throws InterruptedException, IOException {
UNCOV
304
        String source = gf.getFormattedContent();
×
NEW
305
        writeFile(source, gf.getFileEncoding().orElse(null), gf, warnings, false, Merger.noMerge());
×
NEW
306
    }
×
307

308
    private void writeGeneratedXmlFile(GeneratedXmlFile gf, XmlFormatter xmlFormatter, List<String> warnings)
309
            throws InterruptedException, IOException {
NEW
310
        String source = xmlFormatter.getFormattedContent(gf.getDocument());
×
NEW
311
        writeFile(source, "UTF-8", gf, warnings, true, XmlFileMergerJaxp::getMergedSource); //$NON-NLS-1$
×
UNCOV
312
    }
×
313

314
    private void writeFile(String content, @Nullable String encoding, GeneratedFile gf, List<String> warnings,
315
                           boolean mergeEnabled, Merger merger)
316
            throws InterruptedException, IOException {
317
        try {
NEW
318
            File directory = shellCallback.getDirectory(gf.getTargetProject(), gf.getTargetPackage());
×
NEW
319
            Path targetFile = directory.toPath().resolve(gf.getFileName());
×
320
            if (Files.exists(targetFile)) {
×
NEW
321
                if (mergeEnabled && gf.isMergeable()) {
×
NEW
322
                    content = merger.apply(content, targetFile.toFile());
×
323
                } else if (isOverwriteEnabled) {
×
324
                    warnings.add(getString("Warning.11", targetFile.toFile().getAbsolutePath())); //$NON-NLS-1$
×
325
                } else {
NEW
326
                    targetFile = getUniqueFileName(directory, gf.getFileName());
×
327
                    warnings.add(getString("Warning.2", targetFile.toFile().getAbsolutePath())); //$NON-NLS-1$
×
328
                }
329
            }
330

331
            progressCallback.checkCancel();
×
332
            progressCallback.startTask(getString("Progress.15", targetFile.toString())); //$NON-NLS-1$
×
NEW
333
            writeFile(targetFile.toFile(), content, encoding);
×
334
        } catch (ShellException e) {
×
335
            warnings.add(e.getMessage());
×
336
        }
×
337
    }
×
338

339
    /**
340
     * Writes, or overwrites, the contents of the specified file.
341
     *
342
     * @param file
343
     *            the file
344
     * @param content
345
     *            the content
346
     * @param fileEncoding
347
     *            the file encoding
348
     * @throws IOException
349
     *             Signals that an I/O exception has occurred.
350
     */
351
    private void writeFile(File file, String content, @Nullable String fileEncoding) throws IOException {
NEW
352
        Charset cs = mapStringValueOrElseGet(fileEncoding, Charset::forName, Charset::defaultCharset);
×
NEW
353
        try (OutputStream outputStream = Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE,
×
354
                StandardOpenOption.TRUNCATE_EXISTING)) {
NEW
355
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, cs)) {
×
NEW
356
                try (BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) {
×
NEW
357
                    bufferedWriter.write(content);
×
358
                }
359
            }
360
        }
361
    }
×
362

363
    /**
364
     * Gets the unique file name.
365
     *
366
     * @param directory
367
     *            the directory
368
     * @param fileName
369
     *            the file name
370
     * @return the unique file name
371
     */
372
    private Path getUniqueFileName(File directory, String fileName) {
373
        Path answer = null;
×
374

375
        // try up to 1000 times to generate a unique file name
376
        StringBuilder sb = new StringBuilder();
×
377
        for (int i = 1; i < 1000; i++) {
×
378
            sb.setLength(0);
×
379
            sb.append(fileName);
×
380
            sb.append('.');
×
381
            sb.append(i);
×
382

383
            Path testFile = directory.toPath().resolve(sb.toString());
×
384
            if (Files.notExists(testFile)) {
×
385
                answer = testFile;
×
386
                break;
×
387
            }
388
        }
389

390
        if (answer == null) {
×
391
            throw new InternalException(getString("RuntimeError.3", directory.getAbsolutePath())); //$NON-NLS-1$
×
392
        }
393

394
        return answer;
×
395
    }
396

397
    /**
398
     * Returns the list of generated Java files after a call to one of the generate methods.
399
     * This is useful if you prefer to process the generated files yourself and do not want
400
     * the generator to write them to disk.
401
     *
402
     * @return the list of generated Java files
403
     */
404
    public List<GeneratedJavaFile> getGeneratedJavaFiles() {
405
        return generationResultsList.stream()
1✔
406
                .map(GenerationResults::generatedJavaFiles)
1✔
407
                .flatMap(Collection::stream)
1✔
408
                .toList();
1✔
409
    }
410

411
    /**
412
     * Returns the list of generated Kotlin files after a call to one of the generate methods.
413
     * This is useful if you prefer to process the generated files yourself and do not want
414
     * the generator to write them to disk.
415
     *
416
     * @return the list of generated Kotlin files
417
     */
418
    public List<GeneratedKotlinFile> getGeneratedKotlinFiles() {
419
        return generationResultsList.stream()
1✔
420
                .map(GenerationResults::generatedKotlinFiles)
1✔
421
                .flatMap(Collection::stream)
1✔
422
                .toList();
1✔
423
    }
424

425
    /**
426
     * Returns the list of generated XML files after a call to one of the generate methods.
427
     * This is useful if you prefer to process the generated files yourself and do not want
428
     * the generator to write them to disk.
429
     *
430
     * @return the list of generated XML files
431
     */
432
    public List<GeneratedXmlFile> getGeneratedXmlFiles() {
433
        return generationResultsList.stream()
1✔
434
                .map(GenerationResults::generatedXmlFiles)
1✔
435
                .flatMap(Collection::stream)
1✔
436
                .toList();
1✔
437
    }
438

439
    /**
440
     * Returns the list of generated generic files after a call to one of the generate methods.
441
     * This is useful if you prefer to process the generated files yourself and do not want
442
     * the generator to write them to disk.
443
     *
444
     * <p>The list will be empty unless you have used a plugin that generates generic files
445
     * or are using a custom runtime.
446
     *
447
     * @return the list of generated generic files
448
     */
449
    public List<GenericGeneratedFile> getGeneratedGenericFiles() {
450
        return generationResultsList.stream()
×
451
                .map(GenerationResults::generatedGenericFiles)
×
452
                .flatMap(Collection::stream)
×
453
                .toList();
×
454
    }
455

456
    private record ContextValuesAndTables(CalculatedContextValues contextValues,
1✔
457
                                          List<IntrospectedTable> introspectedTables) { }
458

459
    @FunctionalInterface
460
    private interface Merger {
461
        String apply(String newContent, File existingContent) throws ShellException;
462

463
        static Merger noMerge() {
NEW
464
            return (newContent, existingContent) -> newContent;
×
465
        }
466
    }
467

468
    public static class Builder {
1✔
469
        private @Nullable Configuration configuration;
470
        private @Nullable ShellCallback shellCallback;
471
        private @Nullable ProgressCallback progressCallback;
472
        private final Set<String> contextIds = new HashSet<>();
1✔
473
        private final Set<String> fullyQualifiedTableNames = new HashSet<>();
1✔
474
        private boolean isOverwriteEnabled = false;
1✔
475
        private boolean isJavaFileMergeEnabled = false;
1✔
476

477
        public Builder withConfiguration(Configuration configuration) {
478
            this.configuration = configuration;
1✔
479
            return this;
1✔
480
        }
481

482
        public Builder withShellCallback(ShellCallback shellCallback) {
483
            this.shellCallback = shellCallback;
1✔
484
            return this;
1✔
485
        }
486

487
        public Builder withProgressCallback(@Nullable ProgressCallback progressCallback) {
488
            this.progressCallback = progressCallback;
1✔
489
            return this;
1✔
490
        }
491

492
        /**
493
         * Set of context IDs to use in generation. Only the contexts with an id specified in this set will run.
494
         * If the set is empty, then all contexts are run.
495
         *
496
         * @param contextIds
497
         *            a set of contextIds to use in code generation
498
         *
499
         * @return this builder
500
         */
501
        public Builder withContextIds(Set<String> contextIds) {
502
            this.contextIds.addAll(contextIds);
1✔
503
            return this;
1✔
504
        }
505

506
        /**
507
         *  Set of table names to generate. The elements of the set must be Strings that exactly match what's
508
         *  specified in the configuration. For example, if a table name = "foo" and schema = "bar", then the fully
509
         *  qualified table name is "foo.bar". If the Set is empty, then all tables in the configuration
510
         *  will be used for code generation.
511
         *
512
         * @param fullyQualifiedTableNames
513
         *            a set of table names to use in code generation
514
         *
515
         * @return this builder
516
         */
517
        public Builder withFullyQualifiedTableNames(Set<String> fullyQualifiedTableNames) {
518
            this.fullyQualifiedTableNames.addAll(fullyQualifiedTableNames);
1✔
519
            return this;
1✔
520
        }
521

522
        /**
523
         * If true, then newly generated files will overwrite existing files if there is a collision.
524
         * If false, then newly generated files will be written with a unique name when there is a collision.
525
         *
526
         * <p>The default is <code>false</code></p>
527
         *
528
         * @param overwriteEnabled where newly generated files should overwrite existing files if there is a collision
529
         * @return this builder
530
         */
531
        public Builder withOverwriteEnabled(boolean overwriteEnabled) {
532
            this.isOverwriteEnabled = overwriteEnabled;
1✔
533
            return this;
1✔
534
        }
535

536
        /**
537
         * If true, then newly generated Java files will be merged if they collide with existing files.
538
         * If false, then the {@link #withOverwriteEnabled(boolean)} value governs what happens on a collision.
539
         *
540
         * <p>The default is <code>false</code></p>
541
         *
542
         * @param javaFileMergeEnabled where the Java file merger support should be enabled
543
         * @return this builder
544
         */
545
        public Builder withJavaFileMergeEnabled(boolean javaFileMergeEnabled) {
546
            this.isJavaFileMergeEnabled = javaFileMergeEnabled;
1✔
547
            return this;
1✔
548
        }
549

550
        public MyBatisGenerator build() {
551
            return new MyBatisGenerator(this);
1✔
552
        }
553
    }
554
}
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