|
32 | 32 |
|
33 | 33 | import java.util.ArrayList;
|
34 | 34 | import java.util.List;
|
| 35 | +import java.util.Objects; |
35 | 36 | import java.util.Optional;
|
| 37 | +import java.util.function.Consumer; |
36 | 38 |
|
37 | 39 | /**
|
38 | 40 | * The Mybatis dynamic code generator builder.
|
|
43 | 45 | public class MybatisDynamicCodeGenerator {
|
44 | 46 |
|
45 | 47 | private final ContextGeneratorFactory contextGeneratorFactory = new ContextGeneratorFactory();
|
| 48 | + private Consumer<Configuration> configurationCustomizer; |
46 | 49 |
|
47 | 50 | private MybatisDynamicCodeGenerator() {
|
48 | 51 |
|
@@ -105,13 +108,27 @@ public static MybatisDynamicCodeGenerator withYamlConfiguration(String configura
|
105 | 108 | return new MybatisDynamicCodeGenerator(new YamlGeneratorPropertiesLoader(configurationFileName));
|
106 | 109 | }
|
107 | 110 |
|
| 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 | + |
108 | 122 | /**
|
109 | 123 | * Execute generate action.
|
110 | 124 | */
|
111 | 125 | public void generate() {
|
112 | 126 | GeneratorProperties generatorProperties = GeneratorPropertiesHolder.getInstance().getGeneratorProperties();
|
113 | 127 | generatorProperties.validate();
|
114 | 128 | Configuration configuration = this.getConfiguration(generatorProperties);
|
| 129 | + if (Objects.nonNull(this.configurationCustomizer)) { |
| 130 | + this.configurationCustomizer.accept(configuration); |
| 131 | + } |
115 | 132 | DefaultShellCallback callback = new DefaultShellCallback(generatorProperties.isOverwrite());
|
116 | 133 | List<String> warnings = new ArrayList<>();
|
117 | 134 | try {
|
|
0 commit comments