Skip to content

Commit 228dbd3

Browse files
author
GangCheng
committed
add configuration customizer to generator
1 parent c47aaf1 commit 228dbd3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mybatis-r2dbc-generator/src/main/java/pro/chenggang/project/reactive/mybatis/support/generator/core/MybatisDynamicCodeGenerator.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
import java.util.ArrayList;
3434
import java.util.List;
35+
import java.util.Objects;
3536
import java.util.Optional;
37+
import java.util.function.Consumer;
3638

3739
/**
3840
* The Mybatis dynamic code generator builder.
@@ -43,6 +45,7 @@
4345
public class MybatisDynamicCodeGenerator {
4446

4547
private final ContextGeneratorFactory contextGeneratorFactory = new ContextGeneratorFactory();
48+
private Consumer<Configuration> configurationCustomizer;
4649

4750
private MybatisDynamicCodeGenerator() {
4851

@@ -105,13 +108,27 @@ public static MybatisDynamicCodeGenerator withYamlConfiguration(String configura
105108
return new MybatisDynamicCodeGenerator(new YamlGeneratorPropertiesLoader(configurationFileName));
106109
}
107110

111+
/**
112+
* Customize configuration mybatis dynamic code generator.
113+
*
114+
* @param configurationCustomizer the configuration customizer
115+
* @return the mybatis dynamic code generator
116+
*/
117+
public MybatisDynamicCodeGenerator customizeConfiguration(Consumer<Configuration> configurationCustomizer) {
118+
this.configurationCustomizer = configurationCustomizer;
119+
return this;
120+
}
121+
108122
/**
109123
* Execute generate action.
110124
*/
111125
public void generate() {
112126
GeneratorProperties generatorProperties = GeneratorPropertiesHolder.getInstance().getGeneratorProperties();
113127
generatorProperties.validate();
114128
Configuration configuration = this.getConfiguration(generatorProperties);
129+
if (Objects.nonNull(this.configurationCustomizer)) {
130+
this.configurationCustomizer.accept(configuration);
131+
}
115132
DefaultShellCallback callback = new DefaultShellCallback(generatorProperties.isOverwrite());
116133
List<String> warnings = new ArrayList<>();
117134
try {

0 commit comments

Comments
 (0)