diff --git a/java-pojo-generator-mojo-example/pom.xml b/java-pojo-generator-mojo-example/pom.xml index 91fee19..ff3505f 100644 --- a/java-pojo-generator-mojo-example/pom.xml +++ b/java-pojo-generator-mojo-example/pom.xml @@ -70,6 +70,7 @@ generatePojo + true jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM '${project.basedir}/init.sql' org.h2.Driver diff --git a/java-pojo-generator-mojo/src/main/java/org/db2code/generator/java/pojo/mojo/PojoMojo.java b/java-pojo-generator-mojo/src/main/java/org/db2code/generator/java/pojo/mojo/PojoMojo.java index f4b340c..d3e6a2c 100644 --- a/java-pojo-generator-mojo/src/main/java/org/db2code/generator/java/pojo/mojo/PojoMojo.java +++ b/java-pojo-generator-mojo/src/main/java/org/db2code/generator/java/pojo/mojo/PojoMojo.java @@ -38,6 +38,7 @@ public class PojoMojo extends AbstractMojo { @Parameter private String ext; @Parameter private DateImpl dateImpl; + @Parameter private boolean includeGenerationInfo; public void execute() { if (isWindows()) { @@ -66,7 +67,8 @@ public void execute() { this.targetFolder, this.baseDir, ext, - dateImpl)); + dateImpl, + includeGenerationInfo)); } public static boolean isWindows() { diff --git a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/ExecutorParams.java b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/ExecutorParams.java index 77d7c36..b6e44d1 100644 --- a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/ExecutorParams.java +++ b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/ExecutorParams.java @@ -12,6 +12,7 @@ public class ExecutorParams { private final String baseDir; private final String ext; private final DateImpl dateImpl; + private final boolean includeGenerationInfo; public ExecutorParams( Collection extractionParameters, @@ -20,7 +21,8 @@ public ExecutorParams( String targetFolder, String baseDir, String ext, - DateImpl dateImpl) { + DateImpl dateImpl, + boolean includeGenerationInfo) { this.extractionParameters = extractionParameters; this.templates = templates; this.targetPackage = targetPackage; @@ -28,6 +30,7 @@ public ExecutorParams( this.baseDir = baseDir; this.ext = ext; this.dateImpl = dateImpl; + this.includeGenerationInfo = includeGenerationInfo; } public Collection getExtractionParameters() { @@ -57,4 +60,8 @@ public String getExt() { public DateImpl getDateImpl() { return dateImpl; } + + public boolean isIncludeGenerationInfo() { + return includeGenerationInfo; + } } diff --git a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/GeneratorExecutor.java b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/GeneratorExecutor.java index 8e26d4b..7301826 100644 --- a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/GeneratorExecutor.java +++ b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/GeneratorExecutor.java @@ -30,7 +30,11 @@ public void execute(ExecutorParams params) { dateImpl = DateImpl.UTIL_DATE; } - new JavaDatabaseAdapter(metadata, params.getTargetPackage(), dateImpl) + new JavaDatabaseAdapter( + metadata, + params.getTargetPackage(), + dateImpl, + params.isIncludeGenerationInfo()) .getClasses() .forEach( javaClass -> diff --git a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaClassAdapter.java b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaClassAdapter.java index 54adfa9..3f45f91 100644 --- a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaClassAdapter.java +++ b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaClassAdapter.java @@ -1,5 +1,7 @@ package org.db2code.generator.java.pojo.adapter; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Collection; import java.util.stream.Collectors; import org.db2code.convert.JavaPropertyConverter; @@ -9,11 +11,17 @@ public class JavaClassAdapter { private final RawTable rawTable; private final String targetPackage; private final DateImpl dateImpl; + private final boolean includeGenerationInfo; - public JavaClassAdapter(RawTable rawTable, String targetPackage, DateImpl dateImpl) { + public JavaClassAdapter( + RawTable rawTable, + String targetPackage, + DateImpl dateImpl, + boolean includeGenerationInfo) { this.rawTable = rawTable; this.targetPackage = targetPackage; this.dateImpl = dateImpl; + this.includeGenerationInfo = includeGenerationInfo; } public String getClassName() { @@ -33,4 +41,13 @@ public Collection getProperties() { .map(rawColumn -> new JavaPropertyAdapter(rawTable, rawColumn, dateImpl)) .collect(Collectors.toList()); } + + public String getGenerationInfo() { + if (includeGenerationInfo) { + return "Generated by DB2Code at: " + + LocalDateTime.now(ZoneId.systemDefault()).toString(); + } else { + return null; + } + } } diff --git a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaDatabaseAdapter.java b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaDatabaseAdapter.java index 0f2c9e2..2739e31 100644 --- a/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaDatabaseAdapter.java +++ b/java-pojo-generator/src/main/java/org/db2code/generator/java/pojo/adapter/JavaDatabaseAdapter.java @@ -9,17 +9,25 @@ public class JavaDatabaseAdapter { private final RawDatabaseMetadata rawDatabaseMetadata; private final String targetPackage; private final DateImpl dateImpl; + private final boolean includeGenerationInfo; public JavaDatabaseAdapter( - RawDatabaseMetadata rawDatabaseMetadata, String targetPackage, DateImpl dateImpl) { + RawDatabaseMetadata rawDatabaseMetadata, + String targetPackage, + DateImpl dateImpl, + boolean includeGenerationInfo) { this.rawDatabaseMetadata = rawDatabaseMetadata; this.targetPackage = targetPackage; this.dateImpl = dateImpl; + this.includeGenerationInfo = includeGenerationInfo; } public Collection getClasses() { return rawDatabaseMetadata.getTables().stream() - .map((RawTable rawTable) -> new JavaClassAdapter(rawTable, targetPackage, dateImpl)) + .map( + (RawTable rawTable) -> + new JavaClassAdapter( + rawTable, targetPackage, dateImpl, includeGenerationInfo)) .collect(Collectors.toList()); } } diff --git a/java-pojo-generator/src/main/resources/pojo.mustache b/java-pojo-generator/src/main/resources/pojo.mustache index c9f9a22..51a9519 100644 --- a/java-pojo-generator/src/main/resources/pojo.mustache +++ b/java-pojo-generator/src/main/resources/pojo.mustache @@ -1,7 +1,9 @@ package {{package}}; /** {{rawTable.remarks}} - {{rawTable.tableCat}}.{{rawTable.tableSchem}}.{{rawTable.tableName}} + {{rawTable.tableCat}}.{{rawTable.tableSchem}}.{{rawTable.tableName}}{{#generationInfo}} + + {{generationInfo}}{{/generationInfo}} */ public class {{className}} { {{#properties}} diff --git a/java-pojo-generator/src/main/resources/spring-data.mustache b/java-pojo-generator/src/main/resources/spring-data.mustache index 2250643..ece38aa 100644 --- a/java-pojo-generator/src/main/resources/spring-data.mustache +++ b/java-pojo-generator/src/main/resources/spring-data.mustache @@ -5,7 +5,9 @@ import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Table; /** {{rawTable.remarks}} - {{rawTable.tableCat}}.{{rawTable.tableSchem}}.{{rawTable.tableName}} + {{rawTable.tableCat}}.{{rawTable.tableSchem}}.{{rawTable.tableName}}{{#generationInfo}} + + {{generationInfo}}{{/generationInfo}} */ @Table("{{rawTable.tableName}}") public class {{className}} { diff --git a/java-pojo-generator/src/test/java/org/db2code/generator/java/pojo/GeneratorExecutorTest.java b/java-pojo-generator/src/test/java/org/db2code/generator/java/pojo/GeneratorExecutorTest.java index bfca6d0..f79d067 100644 --- a/java-pojo-generator/src/test/java/org/db2code/generator/java/pojo/GeneratorExecutorTest.java +++ b/java-pojo-generator/src/test/java/org/db2code/generator/java/pojo/GeneratorExecutorTest.java @@ -71,7 +71,8 @@ public void test() throws IOException { TARGET_FOLDER, dir, null, - DateImpl.UTIL_DATE)); + DateImpl.UTIL_DATE, + false)); Arrays.stream( Objects.requireNonNull(