|
4 | 4 | import java.nio.file.Path;
|
5 | 5 |
|
6 | 6 | import org.jooq.codegen.GenerationTool;
|
7 |
| -import org.jooq.meta.jaxb.Configuration; |
8 |
| -import org.jooq.meta.jaxb.Database; |
9 |
| -import org.jooq.meta.jaxb.Generate; |
10 |
| -import org.jooq.meta.jaxb.Generator; |
11 |
| -import org.jooq.meta.jaxb.Property; |
12 |
| -import org.jooq.meta.jaxb.Strategy; |
13 |
| -import org.jooq.meta.jaxb.Target; |
| 7 | +import org.jooq.meta.jaxb.*; |
14 | 8 |
|
15 | 9 | public class AdamJooqMetamodelGenerator {
|
16 | 10 |
|
17 |
| - private String packageName; |
18 |
| - private Path outputPath; |
19 |
| - private String source; |
20 |
| - private String jooqConfig; |
21 |
| - |
22 |
| - public AdamJooqMetamodelGenerator(String packageName, Path outputPath, String source, String jooqConfig) { |
23 |
| - this.packageName = packageName; |
24 |
| - this.outputPath = outputPath; |
25 |
| - this.source = source; |
26 |
| - this.jooqConfig = jooqConfig; |
27 |
| - } |
28 |
| - |
29 |
| - public void run() throws Exception { |
30 |
| - Configuration configuration; |
31 |
| - if (jooqConfig != null) { |
32 |
| - configuration = GenerationTool.load(new ByteArrayInputStream(jooqConfig.getBytes("UTF-8"))); |
33 |
| - } else { |
34 |
| - configuration = buildConfiguration(); |
35 |
| - } |
36 |
| - GenerationTool.generate(configuration); |
37 |
| - } |
38 |
| - |
39 |
| - private Configuration buildConfiguration() { |
40 |
| - Configuration configuration; |
41 |
| - configuration = new Configuration(); |
42 |
| - |
43 |
| - Generator generator = new Generator(); |
44 |
| - Database database = new Database(); |
45 |
| - database.setName(AdamDatabase.class.getName()); |
46 |
| - database.getProperties().add(new Property().withKey(AdamDatabase.SOURCE_PROPERTY).withValue(source)); |
47 |
| - generator.setDatabase(database); |
48 |
| - |
49 |
| - Strategy strategy = new Strategy(); |
50 |
| - strategy.setName(TableSuffixGeneratorStrategy.class.getName()); |
51 |
| - generator.setStrategy(strategy); |
52 |
| - |
53 |
| - Generate generate = new Generate(); |
54 |
| - generate.setGlobalObjectReferences(true); |
55 |
| - generate.setJavaTimeTypes(true); |
56 |
| - generator.setGenerate(generate); |
57 |
| - |
58 |
| - Target target = new Target(); |
59 |
| - target.setPackageName(packageName); |
60 |
| - target.setDirectory(outputPath.toString()); |
61 |
| - generator.setTarget(target); |
62 |
| - configuration.setGenerator(generator); |
63 |
| - return configuration; |
64 |
| - } |
| 11 | + private final String packageName; |
| 12 | + private final Path outputPath; |
| 13 | + private final String source; |
| 14 | + private final String jooqConfig; |
| 15 | + |
| 16 | + public AdamJooqMetamodelGenerator(String packageName, Path outputPath, String source, String jooqConfig) { |
| 17 | + this.packageName = packageName; |
| 18 | + this.outputPath = outputPath; |
| 19 | + this.source = source; |
| 20 | + this.jooqConfig = jooqConfig; |
| 21 | + } |
| 22 | + |
| 23 | + public void run() throws Exception { |
| 24 | + Configuration configuration; |
| 25 | + if (jooqConfig != null) { |
| 26 | + configuration = GenerationTool.load(new ByteArrayInputStream(jooqConfig.getBytes("UTF-8"))); |
| 27 | + } else { |
| 28 | + configuration = buildConfiguration(); |
| 29 | + } |
| 30 | + GenerationTool.generate(configuration); |
| 31 | + } |
| 32 | + |
| 33 | + private Configuration buildConfiguration() { |
| 34 | + Configuration configuration; |
| 35 | + configuration = new Configuration(); |
| 36 | + |
| 37 | + Generator generator = new Generator(); |
| 38 | + Database database = new Database(); |
| 39 | + database.setName(AdamDatabase.class.getName()); |
| 40 | + database.getProperties().add(new Property().withKey(AdamDatabase.SOURCE_PROPERTY).withValue(source)); |
| 41 | + generator.setDatabase(database); |
| 42 | + |
| 43 | + Strategy strategy = new Strategy(); |
| 44 | + strategy.setName(TableSuffixGeneratorStrategy.class.getName()); |
| 45 | + generator.setStrategy(strategy); |
| 46 | + |
| 47 | + Generate generate = new Generate(); |
| 48 | + generate.setGlobalObjectReferences(true); |
| 49 | + generate.setJavaTimeTypes(true); |
| 50 | + generate.setPojos(true); |
| 51 | + generate.setFluentSetters(true); |
| 52 | + generator.setGenerate(generate); |
| 53 | + |
| 54 | + Target target = new Target(); |
| 55 | + target.setPackageName(packageName); |
| 56 | + target.setDirectory(outputPath.toString()); |
| 57 | + generator.setTarget(target); |
| 58 | + configuration.setGenerator(generator); |
| 59 | + return configuration; |
| 60 | + } |
65 | 61 |
|
66 | 62 | }
|
0 commit comments