From 2d10bf7d88f8328f09c564c6ad36a54ec13b784d Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:34:38 -0300 Subject: [PATCH 01/43] test feature/submodule-core-plugin-e --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c7663b5..7e3a0d6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL" on: push: - branches: [ main ] + branches: [ feature/submodule-core-plugin-e ] pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: [ feature/submodule-core-plugin-e ] schedule: - cron: '35 12 * * 1' @@ -32,7 +32,7 @@ jobs: strategy: fail-fast: false matrix: - language: [ java ] + language: [ 'java' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support From e8c8e0d8749dd441f3dfa6b76d0ef0352b8c413a Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:39:22 -0300 Subject: [PATCH 02/43] Update codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7e3a0d6..5b8b6cd 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -17,8 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ feature/submodule-core-plugin-e ] - schedule: - - cron: '35 12 * * 1' jobs: analyze: From 65d65ab0542bd2a4628084b58f0e939a2629dc9c Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:41:59 -0300 Subject: [PATCH 03/43] fix CQL --- file.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 file.txt diff --git a/file.txt b/file.txt deleted file mode 100644 index e69de29..0000000 From 751a4c679f3042a09e063200fa7f3eaf84ec91bf Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:45:18 -0300 Subject: [PATCH 04/43] Update codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5b8b6cd..ca5af78 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,14 +9,14 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: "CodeQL main" on: push: - branches: [ feature/submodule-core-plugin-e ] + branches: [ main ] pull_request: # The branches below must be a subset of the branches above - branches: [ feature/submodule-core-plugin-e ] + branches: [ main ] jobs: analyze: From fd27e7f782c6a6b9e354b66cf1ed98a4fc4af1a6 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:51:14 -0300 Subject: [PATCH 05/43] fix: Unsafe Deserialization in jackson-databind --- sqlschema2java-core/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 3f555cd..f2d35f6 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -165,19 +165,19 @@ com.fasterxml.jackson.core jackson-core - 2.4.2 + 2.13.2 com.fasterxml.jackson.core jackson-annotations - 2.4.2 + 2.13.2 com.fasterxml.jackson.core jackson-databind - 2.4.2 + 2.13.2.2 From ca7f540f07348ada6e96c3fb5c56618bc64efcb2 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 19:54:34 -0300 Subject: [PATCH 06/43] fix: TemporaryFolder on unix-like junit --- sqlschema2java-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index f2d35f6..510cc8a 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -183,7 +183,7 @@ junit junit - 4.10 + 4.13.2 test From c5251d41ec9512f5819d70d37497ed1ce40634f8 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 22:14:29 -0300 Subject: [PATCH 07/43] fix: README.md --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 35fdab1..b6bb151 100644 --- a/README.md +++ b/README.md @@ -1 +1,67 @@ -# sqlschema2java \ No newline at end of file +# SQLSchema2Java [![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) + +![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) + + +_sqlschema2java_ generates Java types from SQLSchema and annotate those types for data-binding with Jackson 2.x, Javax Persistence and Spring Repository. + +You can use sqlschema2java as a Maven plugin. +[**Try at the sample project exemple**](https://github.com/Sassine/sqlschema2java/tree/main/sqlschema2java-example) + +## Implementation + +#### A very simple Maven example: +```xml +pom.xml + + + dev.sassine.api + sqlschema2java-maven-plugin + 1.0.0 + + + + sqlschema2java + + + + + /user/home/example.sql + dev.sassine.api + true + false + + + + + + + github + GitHub Packages SQLSchema2Java + https://maven.pkg.github.com/Sassine/sqlschema2java + + +``` +### Parameters +| Name | required | type | description | +|--|--|--|--| +| sourceDirectory | true | String | SQL file path | +| packageName | true | String | package name with points that will be generated | +| useAutoIncrement| false | Boolean| disable or enable whether the primary key will have its value generated automatically | +| isPostgres| true | Boolean | disable or enable query conversion compatible with postgres database | + + +##### Run command +```bash +mvn dev.sassine.api:sqlschema2java-maven-plugin:generate +``` +Successful ✨ + +## Contributing +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +Please make sure to update tests as appropriate. + +## License + +[MIT ](https://github.com/Sassine/sqlschema2java/blob/main/LICENSE) \ No newline at end of file From e8eb7b6cb4fcca87c1f5acd2fc7d833f0ccbd59b Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 23:34:59 -0300 Subject: [PATCH 08/43] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6bb151..2f00c64 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ Pull requests are welcome. For major changes, please open an issue first to disc Please make sure to update tests as appropriate. +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/P5P8C2H8Q) + ## License -[MIT ](https://github.com/Sassine/sqlschema2java/blob/main/LICENSE) \ No newline at end of file +[MIT ](https://github.com/Sassine/sqlschema2java/blob/main/LICENSE) From bd1efd38111f59861a349a08822214137bb504cd Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 9 Apr 2022 23:37:21 -0300 Subject: [PATCH 09/43] Create funding.yml --- .github/funding.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/funding.yml diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..13c945c --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,2 @@ +github: Sassine +ko_fi: sassineasmar From 07e321306a70dff706233a7d331553a61dd1d367 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sun, 10 Apr 2022 02:12:23 -0300 Subject: [PATCH 10/43] add: readme link to Getting started --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b6bb151..4fa530a 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ _sqlschema2java_ generates Java types from SQLSchema and annotate those types fo You can use sqlschema2java as a Maven plugin. [**Try at the sample project exemple**](https://github.com/Sassine/sqlschema2java/tree/main/sqlschema2java-example) +[**Read Getting Started**](https://github.com/Sassine/sqlschema2java/wiki/Getting-Started) + ## Implementation #### A very simple Maven example: From ad5d70de4b534697818700212becdb5e6c570199 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 14:15:08 -0300 Subject: [PATCH 11/43] refactor: JPA Repository Import and expands class Interface --- .../export/builder/factory/impl/RepositoryFactory.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/RepositoryFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/RepositoryFactory.java index 1c1b47f..b57a347 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/RepositoryFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/RepositoryFactory.java @@ -16,6 +16,7 @@ import org.burningwave.core.classes.GenericSourceGenerator; import org.burningwave.core.classes.TypeDeclarationSourceGenerator; import org.burningwave.core.classes.UnitSourceGenerator; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import dev.sassine.api.structure.export.builder.factory.Factory; @@ -25,8 +26,6 @@ public class RepositoryFactory implements Factory { private static final Logger log = getLogger(); - private static final String PACKAGE_JPAREPOSITORY = "org.springframework.data.jpa.repository.JpaRepository"; - private static final String CLASSNAME_JPAREPOSITORY = "JpaRepository"; private static final String DOT_REPOSITORY = ".repository"; private static final String ENTITY_REPOSITORY = "EntityRepository"; private static final String ENTITY = "Entity"; @@ -39,7 +38,6 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam ClassSourceGenerator interfaceClass = this.buildClassSource(entityModel, nameClass); log.debug("InterfaceRepository builded"); importEntityClass(nameClass, packageName, gen); - gen.addImport(PACKAGE_JPAREPOSITORY); gen.addClass(interfaceClass); store(gen); log.debug("Repository EntityClass ({}) stored", nameClass); @@ -47,8 +45,8 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam private ClassSourceGenerator buildClassSource(EntityModel entityModel, String nameClass) { return ClassSourceGenerator - .createInterface(TypeDeclarationSourceGenerator.create(ENTITY_REPOSITORY)) - .expands(TypeDeclarationSourceGenerator.create(CLASSNAME_JPAREPOSITORY) + .createInterface(TypeDeclarationSourceGenerator.create(nameClass.concat(ENTITY_REPOSITORY))) + .expands(TypeDeclarationSourceGenerator.create(JpaRepository.class) .addGeneric(GenericSourceGenerator.create(nameClass.concat(ENTITY))) .addGeneric(GenericSourceGenerator.create(this.getIdClassType(entityModel)))) .addModifier(PUBLIC) From b3ca13f75e6225ca0abeffa8ae19e0d51c8057dd Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 14:17:55 -0300 Subject: [PATCH 12/43] refactor: call method plugin sqlschema2java to generate --- sqlschema2java-core/pom.xml | 2 +- sqlschema2java-example/pom.xml | 4 ++-- sqlschema2java-maven-plugin/pom.xml | 4 ++-- .../api/maven/plugin/start/SqlSchema2Java.java | 16 ++++++---------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 510cc8a..20c23b3 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -6,7 +6,7 @@ dev.sassine.api sqlschema2java-core - 1.0.0-SNAPSHOT + 1.0.1-SNAPSHOT sqlschema2java-core Auto generate Class DTO, Entity and Repository from SQL Query. diff --git a/sqlschema2java-example/pom.xml b/sqlschema2java-example/pom.xml index 85f6335..9967671 100644 --- a/sqlschema2java-example/pom.xml +++ b/sqlschema2java-example/pom.xml @@ -33,11 +33,11 @@ dev.sassine.api sqlschema2java-maven-plugin - 1.0.0-SNAPSHOT + 1.0.1-SNAPSHOT - sqlschema2java + generate diff --git a/sqlschema2java-maven-plugin/pom.xml b/sqlschema2java-maven-plugin/pom.xml index 5bed96c..1c75c88 100644 --- a/sqlschema2java-maven-plugin/pom.xml +++ b/sqlschema2java-maven-plugin/pom.xml @@ -6,7 +6,7 @@ 4.0.0 dev.sassine.api sqlschema2java-maven-plugin - 1.0.0-SNAPSHOT + 1.0.1-SNAPSHOT sqlschema2java-maven-plugin maven-plugin @@ -81,7 +81,7 @@ - 1.0.0-SNAPSHOT + 1.0.1-SNAPSHOT 1.8 1.8 3.6.2 diff --git a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java index ce33952..89d44e7 100644 --- a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java +++ b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java @@ -1,4 +1,7 @@ package dev.sassine.api.maven.plugin.start; +import static dev.sassine.api.structure.Sqlschema2Java.generate; +import static java.lang.String.format; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -7,9 +10,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import dev.sassine.api.structure.Sqlschema2Java; - -@Mojo(name = "sqlschema2java", defaultPhase = LifecyclePhase.NONE) +@Mojo(name = "generate", defaultPhase = LifecyclePhase.NONE) public class SqlSchema2Java extends AbstractMojo { @Parameter(defaultValue = "${project}", required = true, readonly = true) @@ -27,15 +28,10 @@ public class SqlSchema2Java extends AbstractMojo { @Parameter(property = "sql.type.auto.increment.enabled" , defaultValue = "true", required = false, readonly = true) Boolean useAutoIncrement; - @Parameter(property = "log.debug.enabled" , defaultValue = "false", required = false, readonly = true) - String debugEnabled; - - public void execute() throws MojoExecutionException, MojoFailureException { - getLog().info(" "); - Sqlschema2Java.generate(sourceDirectory, isPostgres, useAutoIncrement,packageName); - getLog().info(" "); + getLog().info(format(" packageName %s - sourceDirectory %s - isPostgres %s - useAutoIncrement %s", sourceDirectory, packageName, isPostgres, useAutoIncrement)); + generate(sourceDirectory, isPostgres, useAutoIncrement, packageName); } } From 13e8152602ccdb4856bf1dcb7d484261ebd6012c Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 14:35:01 -0300 Subject: [PATCH 13/43] feature: Adding @JsonDeserialize Local-DateTime/Date/Time in DTO --- sqlschema2java-core/pom.xml | 6 ++++ .../builder/factory/impl/DTOFactory.java | 8 ++--- .../builder/function/ImportBeanFunction.java | 30 ++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 20c23b3..ab1983e 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -180,6 +180,12 @@ 2.13.2.2 + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.13.2 + + junit junit diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java index 4a1ca6a..9320a38 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java @@ -1,7 +1,7 @@ package dev.sassine.api.structure.export.builder.factory.impl; import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importEntityClass; -import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importJavaTime; +import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importJavaTimeAndJSONDeserialize; import static dev.sassine.api.structure.export.builder.function.StoreClassFuncation.store; import static java.lang.String.format; import static java.lang.reflect.Modifier.PUBLIC; @@ -38,7 +38,7 @@ public class DTOFactory implements Factory { private static final String FORMAT_NEW_ENTITY_METHOD = "%s entity = new %s();"; private static final String FORMAT_STRING_FIELDS = "\"%s\""; private static final String FORMAT_PACKAGE_DOT_PACKAGE = "%s.%s"; - private static final String FORMAT_SETTER_EQ_GETTER = "this.%s = entity.get%s();"; + private static final String FORMAT_SET_VALUE = "entity.set%s(this.%s);"; private static final String PARAM_VALUE = "value"; @Override @@ -56,7 +56,7 @@ public void execute(EntityModel entityModel,boolean isAutoGenerated, String name log.debug("Prepare generate ({}) fields", entityModel.getFields().size()); entityModel.getFields().forEach(fieldModel -> { VariableSourceGenerator field = this.buildField(fieldModel); - importJavaTime(gen, fieldModel); + importJavaTimeAndJSONDeserialize(field,gen, fieldModel); this.addFunctionToMethodFunction(fm, fieldModel); log.debug("Adding field in functionMethod toEntity"); clDTO.addField(field); @@ -76,7 +76,7 @@ private void closeMethodFunction(FunctionSourceGenerator functionMethodToEntity) } private void addFunctionToMethodFunction(FunctionSourceGenerator functionMethodToEntity, FieldModel fieldModel) { - functionMethodToEntity.addBodyCodeLine(format(FORMAT_SETTER_EQ_GETTER, fieldModel.getCamelName(), fieldModel.getCamelNameUpper())); + functionMethodToEntity.addBodyCodeLine(format(FORMAT_SET_VALUE, fieldModel.getCamelNameUpper(), fieldModel.getCamelName())); } private VariableSourceGenerator buildField(FieldModel fieldModel) { diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java index 745b5f6..6cdbe52 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java @@ -9,12 +9,21 @@ import java.time.LocalDateTime; import java.time.LocalTime; +import org.burningwave.core.classes.AnnotationSourceGenerator; +import org.burningwave.core.classes.TypeDeclarationSourceGenerator; import org.burningwave.core.classes.UnitSourceGenerator; +import org.burningwave.core.classes.VariableSourceGenerator; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; import dev.sassine.api.structure.model.java.FieldModel; public class ImportBeanFunction { + private static final String PARAM_USING = "using"; private static final String FORMAT_IMPORT_ENTITY_PACKAGE = "%s.domain.%sEntity"; public static void importEntityClass(String nameClass, String packageName, UnitSourceGenerator gen) { @@ -26,5 +35,24 @@ public static void importJavaTime(UnitSourceGenerator gen, FieldModel fieldModel else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) gen.addImport(LocalDate.class); else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) gen.addImport(LocalTime.class); } - + + public static void importJavaTimeAndJSONDeserialize(VariableSourceGenerator field, UnitSourceGenerator gen, + FieldModel fieldModel) { + if (TYPE_LOCAL_DATE_TIME.equals(fieldModel.getType())) { + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, + VariableSourceGenerator + .create(TypeDeclarationSourceGenerator.create(LocalDateTimeDeserializer.class)))); + gen.addImport(LocalDateTime.class); + } else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) { + gen.addImport(LocalDate.class); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, + VariableSourceGenerator + .create(TypeDeclarationSourceGenerator.create(LocalDateDeserializer.class)))); + } else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) { + gen.addImport(LocalTime.class); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, + VariableSourceGenerator + .create(TypeDeclarationSourceGenerator.create(LocalTimeDeserializer.class)))); + } + } } From 0b583aafae40a3a9927bb2dc858da51f9ad115f9 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 15:43:00 -0300 Subject: [PATCH 14/43] version: 1.0.0-beta1 --- pom.xml | 2 +- sqlschema2java-core/pom.xml | 2 +- .../export/builder/factory/impl/EntityFactory.java | 10 ++++++++++ sqlschema2java-example/pom.xml | 4 ++-- sqlschema2java-maven-plugin/pom.xml | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index cf5f2a1..f4957b8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 sqlschema2java - 1.0.0-SNAPSHOT + 1.0.0-beta1 sqlschema2java pom dev.sassine.api diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index ab1983e..fc20ddd 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -6,7 +6,7 @@ dev.sassine.api sqlschema2java-core - 1.0.1-SNAPSHOT + 1.0.0-beta1 sqlschema2java-core Auto generate Class DTO, Entity and Repository from SQL Query. diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java index f5d6e25..c425317 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java @@ -6,6 +6,7 @@ import static java.lang.reflect.Modifier.PRIVATE; import static java.lang.reflect.Modifier.PUBLIC; import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.logging.log4j.LogManager.getLogger; import javax.persistence.Column; @@ -20,6 +21,7 @@ import org.burningwave.core.classes.TypeDeclarationSourceGenerator; import org.burningwave.core.classes.UnitSourceGenerator; import org.burningwave.core.classes.VariableSourceGenerator; +import org.hibernate.annotations.ColumnDefault; import dev.sassine.api.structure.export.builder.factory.Factory; import dev.sassine.api.structure.model.java.EntityModel; @@ -51,6 +53,7 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam entityModel.getFields().forEach(fieldModel -> { VariableSourceGenerator field = this.buildField(fieldModel); importJavaTime(gen, fieldModel); + this.setDefaultValue(field,fieldModel); this.generateEntityPK(isAutoGenerated, fieldModel, field, entityModel); log.debug("Generated EntityPK"); clEntity.addField(field); @@ -61,6 +64,13 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam log.debug("ClassEntity ({}) stored", nameClass); } + private void setDefaultValue(VariableSourceGenerator field, FieldModel fieldModel) { + if(isNotBlank(fieldModel.getDefaultValue())) { + field.addAnnotation(AnnotationSourceGenerator.create(ColumnDefault.class).addParameter("value", + VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, fieldModel.getDefaultValue())))); + } + } + private ClassSourceGenerator buildClassSource(EntityModel entityModel, String nameClass) { return ClassSourceGenerator .create(TypeDeclarationSourceGenerator.create(format(FORMAT_ENTITY_CLASSNAME, nameClass))) diff --git a/sqlschema2java-example/pom.xml b/sqlschema2java-example/pom.xml index 9967671..de957c9 100644 --- a/sqlschema2java-example/pom.xml +++ b/sqlschema2java-example/pom.xml @@ -5,7 +5,7 @@ 4.0.0 dev.sasine.api sqlschema2java-example - 1.0.0-SNAPSHOT + 1.0.0-beta1 pom @@ -33,7 +33,7 @@ dev.sassine.api sqlschema2java-maven-plugin - 1.0.1-SNAPSHOT + 1.0.0-beta1 diff --git a/sqlschema2java-maven-plugin/pom.xml b/sqlschema2java-maven-plugin/pom.xml index 1c75c88..b45d306 100644 --- a/sqlschema2java-maven-plugin/pom.xml +++ b/sqlschema2java-maven-plugin/pom.xml @@ -6,7 +6,7 @@ 4.0.0 dev.sassine.api sqlschema2java-maven-plugin - 1.0.1-SNAPSHOT + 1.0.0-beta1 sqlschema2java-maven-plugin maven-plugin @@ -81,7 +81,7 @@ - 1.0.1-SNAPSHOT + 1.0.0-beta1 1.8 1.8 3.6.2 From 90958ed839dcff0d757dcc2b1c5ea51b78e2d3b8 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 16:07:14 -0300 Subject: [PATCH 15/43] Feature: adding default value Date/Time --- .../export/builder/factory/impl/EntityFactory.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java index c425317..e75b309 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java @@ -2,13 +2,19 @@ import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importJavaTime; import static dev.sassine.api.structure.export.builder.function.StoreClassFuncation.store; +import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE; +import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE_TIME; +import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_TIME; import static java.lang.String.format; import static java.lang.reflect.Modifier.PRIVATE; import static java.lang.reflect.Modifier.PUBLIC; +import static java.util.Objects.nonNull; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.logging.log4j.LogManager.getLogger; +import java.util.Map; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -42,6 +48,11 @@ public class EntityFactory implements Factory { private static final String PARAM_NULLABLE = "nullable"; private static final String PARAM_NAME = "name"; + Map defaultValueLocal = Map.of( + TYPE_LOCAL_DATE, "LocalDate.now()", + TYPE_LOCAL_TIME, "LocalTime.now()", + TYPE_LOCAL_DATE_TIME, "LocalDateTime.now()"); + @Override public void execute(EntityModel entityModel, boolean isAutoGenerated, String nameClass, String packageName) { log.debug("ClassName: ({}) - PackageName: ({}) ", nameClass, packageName); @@ -66,6 +77,8 @@ public void execute(EntityModel entityModel, boolean isAutoGenerated, String nam private void setDefaultValue(VariableSourceGenerator field, FieldModel fieldModel) { if(isNotBlank(fieldModel.getDefaultValue())) { + var value = defaultValueLocal.get(fieldModel.getType()); + if(nonNull(value)) field.setValue(defaultValueLocal.get(fieldModel.getType())); field.addAnnotation(AnnotationSourceGenerator.create(ColumnDefault.class).addParameter("value", VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, fieldModel.getDefaultValue())))); } From 0375e9fe2cef8bc9cd37eb865d8428f9586522e3 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 16:08:36 -0300 Subject: [PATCH 16/43] fix: import .class deserialize object --- .../builder/function/ImportBeanFunction.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java index 6cdbe52..042d043 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java @@ -23,6 +23,9 @@ public class ImportBeanFunction { + private static final String TIME_DESERIALIZER = "LocalTimeDeserializer.class"; + private static final String DATE_DESERIALIZER = "LocalDateDeserializer.class"; + private static final String DATE_TIME_DESERIALIZER = "LocalDateTimeDeserializer.class"; private static final String PARAM_USING = "using"; private static final String FORMAT_IMPORT_ENTITY_PACKAGE = "%s.domain.%sEntity"; @@ -39,20 +42,21 @@ public static void importJavaTime(UnitSourceGenerator gen, FieldModel fieldModel public static void importJavaTimeAndJSONDeserialize(VariableSourceGenerator field, UnitSourceGenerator gen, FieldModel fieldModel) { if (TYPE_LOCAL_DATE_TIME.equals(fieldModel.getType())) { - field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator - .create(TypeDeclarationSourceGenerator.create(LocalDateTimeDeserializer.class)))); gen.addImport(LocalDateTime.class); + gen.addImport(LocalDateTimeDeserializer.class); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, + VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(DATE_TIME_DESERIALIZER)))); } else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) { gen.addImport(LocalDate.class); + gen.addImport(LocalDateDeserializer.class); field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator - .create(TypeDeclarationSourceGenerator.create(LocalDateDeserializer.class)))); + VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(DATE_DESERIALIZER)))); } else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) { gen.addImport(LocalTime.class); + gen.addImport(LocalTimeDeserializer.class); field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator - .create(TypeDeclarationSourceGenerator.create(LocalTimeDeserializer.class)))); + VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(TIME_DESERIALIZER)))); + } } } From 6342e212b71fa8d22953cf99bfa515e31deb7450 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 17:17:29 -0300 Subject: [PATCH 17/43] add badges readme --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fa9fb4c..b1f15f8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -# SQLSchema2Java [![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) +# SQLSchema2Java + +[![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) +[![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) +[![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) +[![GitHub license](https://img.shields.io/github/license/Sassine/sqlschema2java.svg)](https://github.com/Sassine/sqlschema2java/blob/master/LICENSE) + +[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) @@ -68,4 +75,4 @@ Please make sure to update tests as appropriate. ## License -[MIT ](https://github.com/Sassine/sqlschema2java/blob/main/LICENSE) +[![GitHub license](https://img.shields.io/github/license/Sassine/sqlschema2java.svg)](https://github.com/Sassine/sqlschema2java/blob/master/LICENSE) From 05ffccddcbfcca90cf625cff14757f0ee0e49c29 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 17:18:58 -0300 Subject: [PATCH 18/43] add badges readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b1f15f8..ed0129f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ -# SQLSchema2Java +# SQLSchema2Java [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) + [![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) [![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) -[![GitHub license](https://img.shields.io/github/license/Sassine/sqlschema2java.svg)](https://github.com/Sassine/sqlschema2java/blob/master/LICENSE) - -[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From c87d87b44e3aba86ae008dc67acf009ca5cad7fb Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 18:49:44 -0300 Subject: [PATCH 19/43] feature: adding coveralls to project --- .gitignore | 1 + sqlschema2java-core/pom.xml | 81 ++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6661591..b3abc00 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ sqlschema2java-example/src sqlschema2java-maven-plugin/.settings/org.eclipse.jdt.core.prefs sqlschema2java-maven-plugin/.settings/org.eclipse.m2e.core.prefs sqlschema2java-maven-plugin/.settings/org.springframework.ide.eclipse.prefs +bin/ diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index fc20ddd..161b870 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -8,12 +8,16 @@ sqlschema2java-core 1.0.0-beta1 sqlschema2java-core - + Auto generate Class DTO, Entity and Repository from SQL Query. https://sassine.dev/ 11 + 4.3.0 + 0.8.8 + Sassine El-Asmar + UTF-8 @@ -30,6 +34,32 @@ + + + ${project.basedir} + + **LICENSE + + META-INF + + + ${project.basedir}/src/main/resources + + ** + + + + + + ${project.basedir}/src/test/java + + **/*.java + + + + ${project.basedir}/src/test/resources + + org.pitest @@ -80,15 +110,62 @@ maven-compiler-plugin 3.8.0 - ./sql.sql UTF-8 11 11 + + org.eluder.coveralls + coveralls-maven-plugin + ${coveralls-maven-plugin.version} + + + ${project.basedir}/src/main/java + + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + + + **/*SqlListener* + **/*SqlBaseListener* + **/*SqlLexer* + **/*SqlParser* + **/*Main + **/*Sqlschema2Java + + + + org.antlr From 158d5b1098c7e24983ef2dcf37ebb15c29043be7 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 18:54:02 -0300 Subject: [PATCH 20/43] add covarege % in readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ed0129f..aa54ff8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) [![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) +[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=develop)](https://coveralls.io/github/Sassine/sqlschema2java?branch=develop) + ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From 7791ebad6d84ced7e44e039dc9cbea869e07d194 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 15 Apr 2022 18:55:34 -0300 Subject: [PATCH 21/43] add covarege % in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa54ff8..f283b2d 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) -[![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) +[![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) [![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=develop)](https://coveralls.io/github/Sassine/sqlschema2java?branch=develop) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From 977564ff076708e7f895ddb487080eaa14733cef Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 03:52:25 -0300 Subject: [PATCH 22/43] feature: implements unit test - uping covarage margin and script compute covarage in coverall --- .github/workflows/compute-covarage.yml | 22 ++++++ .github/workflows/deploy.yml | 4 +- README.md | 2 +- sqlschema2java-core/pom.xml | 6 +- .../api/structure/model/java/FieldModel.java | 1 - .../structure/model/java/EntityModelTest.java | 25 ++++++ sqlschema2java-example/pom.xml | 76 ++++++++++--------- sqlschema2java-example/runSqlSchema2Java.sh | 2 +- 8 files changed, 96 insertions(+), 42 deletions(-) create mode 100644 .github/workflows/compute-covarage.yml create mode 100644 sqlschema2java-core/src/test/java/dev/sassine/api/structure/model/java/EntityModelTest.java diff --git a/.github/workflows/compute-covarage.yml b/.github/workflows/compute-covarage.yml new file mode 100644 index 0000000..9ba8422 --- /dev/null +++ b/.github/workflows/compute-covarage.yml @@ -0,0 +1,22 @@ +name: Compute coverage + +on: + push: + branches: [ main , develop ] + + +jobs: + compute-coverage: + name: Compute coverage + runs-on: ubuntu-latest + environment: + name: coveralls + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v2.5.0 + with: + java-version: 8 + distribution: 'zulu' + architecture: x64 + - name: Build and test + run: cd sqlschema2java-core && mvn clean test run-coveralls jacoco:report coveralls:report -DrepoToken=${{ secrets.coveralls_repo_token }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3158248..6b04c8b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest needs: publish-core steps: - - name: Sleep for 30 seconds + - name: Sleep for 5 minutes uses: jakejarvis/wait-action@master with: time: '5m' @@ -44,7 +44,7 @@ jobs: with: java-version: '11' distribution: 'adopt' - - name: Publish package SQLSchema2Java Core + - name: Publish package SQLSchema2Java MavenPLugin run: | cd sqlschema2java-maven-plugin mvn --batch-mode deploy diff --git a/README.md b/README.md index f283b2d..56851cc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) [![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) -[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=develop)](https://coveralls.io/github/Sassine/sqlschema2java?branch=develop) +[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg)](https://coveralls.io/github/Sassine/sqlschema2java) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 161b870..a71558a 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -157,8 +157,9 @@ **/*SqlBaseListener* **/*SqlLexer* **/*SqlParser* - **/*Main - **/*Sqlschema2Java + **/*Main* + **/*Sqlschema2Java* + **/builder/** @@ -190,7 +191,6 @@ org.projectlombok lombok 1.18.22 - provided diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/FieldModel.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/FieldModel.java index d95a158..10fba1e 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/FieldModel.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/FieldModel.java @@ -20,7 +20,6 @@ public class FieldModel { private String defaultValue; private Integer minOccurs; private String maxOccurs; - private boolean isEmbedded; public FieldModel(String name) { this.name = name; diff --git a/sqlschema2java-core/src/test/java/dev/sassine/api/structure/model/java/EntityModelTest.java b/sqlschema2java-core/src/test/java/dev/sassine/api/structure/model/java/EntityModelTest.java new file mode 100644 index 0000000..d339b8b --- /dev/null +++ b/sqlschema2java-core/src/test/java/dev/sassine/api/structure/model/java/EntityModelTest.java @@ -0,0 +1,25 @@ +package dev.sassine.api.structure.model.java; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +public class EntityModelTest { + + + @Test + public void getFieldForNameTest() { + var entity = new EntityModel("table", "auto"); + var field = new FieldModel(); + field.setName("teste_1"); + field.setType("Integer"); + entity.getFields().add(field); + var value = entity.getFieldForName("teste_1"); + assertEquals("teste1",value.getCamelName()); + assertEquals("Teste1",value.getCamelNameUpper()); + assertEquals("Integer",value.getType()); + assertNull(entity.getFieldForName("teste_2")); + } + +} diff --git a/sqlschema2java-example/pom.xml b/sqlschema2java-example/pom.xml index de957c9..d50d9f4 100644 --- a/sqlschema2java-example/pom.xml +++ b/sqlschema2java-example/pom.xml @@ -1,12 +1,12 @@ - 4.0.0 - dev.sasine.api - sqlschema2java-example - 1.0.0-beta1 - pom + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + dev.sasine.api + sqlschema2java-example + 1.0.0-beta1 + pom @@ -20,35 +20,43 @@ - + - false - false - ./input.sql - + false + false + ./input.sql + + + + + + dev.sassine.api + sqlschema2java-maven-plugin + 1.0.0-beta1 + + + + generate + + + + + ${is.postgres} + ${path.arquivo} + ${auto.increment.enabled} + false + + + + - - - - dev.sassine.api - sqlschema2java-maven-plugin - 1.0.0-beta1 - - - - generate - - - - - ${is.postgres} - ${path.arquivo} - ${auto.increment.enabled} - false - - - - + + + github + GitHub Packages SQLSchema2Java + https://maven.pkg.github.com/Sassine/sqlschema2java + + \ No newline at end of file diff --git a/sqlschema2java-example/runSqlSchema2Java.sh b/sqlschema2java-example/runSqlSchema2Java.sh index 496b901..f24de46 100644 --- a/sqlschema2java-example/runSqlSchema2Java.sh +++ b/sqlschema2java-example/runSqlSchema2Java.sh @@ -1,3 +1,3 @@ #!/bin/sh -mvn dev.sassine.api:sqlschema2java-maven-plugin:sqlschema2java \ No newline at end of file +mvn dev.sassine.api:sqlschema2java-maven-plugin:generate \ No newline at end of file From 656472a20dd1ad9fd07f914d9a481724548eed5b Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 03:54:17 -0300 Subject: [PATCH 23/43] feature: implements unit test - uping covarage margin and script compute covarage in coverall --- .github/workflows/compute-covarage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compute-covarage.yml b/.github/workflows/compute-covarage.yml index 9ba8422..b4f2c9e 100644 --- a/.github/workflows/compute-covarage.yml +++ b/.github/workflows/compute-covarage.yml @@ -19,4 +19,4 @@ jobs: distribution: 'zulu' architecture: x64 - name: Build and test - run: cd sqlschema2java-core && mvn clean test run-coveralls jacoco:report coveralls:report -DrepoToken=${{ secrets.coveralls_repo_token }} + run: cd sqlschema2java-core && mvn clean test jacoco:report coveralls:report -DrepoToken=${{ secrets.coveralls_repo_token }} From dfe89572755143a6458ea7326f669bb74958dd3e Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 03:57:18 -0300 Subject: [PATCH 24/43] feature: implements unit test - uping covarage margin and script compute covarage in coverall --- .github/workflows/compute-covarage.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compute-covarage.yml b/.github/workflows/compute-covarage.yml index b4f2c9e..4cc9aab 100644 --- a/.github/workflows/compute-covarage.yml +++ b/.github/workflows/compute-covarage.yml @@ -12,11 +12,10 @@ jobs: environment: name: coveralls steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2.5.0 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: - java-version: 8 - distribution: 'zulu' - architecture: x64 + java-version: '11' + distribution: 'adopt' - name: Build and test run: cd sqlschema2java-core && mvn clean test jacoco:report coveralls:report -DrepoToken=${{ secrets.coveralls_repo_token }} From 880fff6a43279c173a3d17b9a398ba4325cff114 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 04:03:30 -0300 Subject: [PATCH 25/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56851cc..0fc4823 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) [![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) -[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg)](https://coveralls.io/github/Sassine/sqlschema2java) +[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=main)](https://coveralls.io/github/Sassine/sqlschema2java?branch=main) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From 2700554b022cefdda2f6e88490618dfde552a3c0 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 04:03:30 -0300 Subject: [PATCH 26/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56851cc..0fc4823 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) [![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) -[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg)](https://coveralls.io/github/Sassine/sqlschema2java) +[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=main)](https://coveralls.io/github/Sassine/sqlschema2java?branch=main) ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From 8baa0935a35953d47740b93abececd8eb393bd4b Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 16 Apr 2022 23:37:28 -0300 Subject: [PATCH 27/43] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0fc4823..59f1f42 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ _sqlschema2java_ generates Java types from SQLSchema and annotate those types for data-binding with Jackson 2.x, Javax Persistence and Spring Repository. +![File SQL -> Funil -> Generate Files DTO, Entity and Repostiory.java](https://sassine.dev/assets/images/funil.png?a=1) + + + You can use sqlschema2java as a Maven plugin. [**Try at the sample project exemple**](https://github.com/Sassine/sqlschema2java/tree/main/sqlschema2java-example) From 2b687e8de423a0a2fb173760cf8c72a849525ee8 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Mon, 18 Apr 2022 17:33:27 -0300 Subject: [PATCH 28/43] refactor: objects called in generate method to EnvModel and mock values in main method --- pom.xml | 2 +- sqlschema2java-core/pom.xml | 60 +++++++++++-------- .../java/dev/sassine/api/structure/Main.java | 13 ++-- .../sassine/api/structure/Sqlschema2Java.java | 16 ++--- .../export/builder/ClassSourceBuilder.java | 15 ++--- .../model/java/EnvironmentModel.java | 22 +++++++ .../api/structure/type/TypeConverter.java | 1 + .../src/test/resources/default.sql | 12 ++++ sqlschema2java-example/pom.xml | 15 ++--- sqlschema2java-maven-plugin/pom.xml | 24 ++++---- .../maven/plugin/start/SqlSchema2Java.java | 15 +++-- 11 files changed, 129 insertions(+), 66 deletions(-) create mode 100644 sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EnvironmentModel.java create mode 100644 sqlschema2java-core/src/test/resources/default.sql diff --git a/pom.xml b/pom.xml index f4957b8..150281e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 sqlschema2java - 1.0.0-beta1 + 1.0.0-beta sqlschema2java pom dev.sassine.api diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index a71558a..fe3fad6 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -6,7 +6,7 @@ dev.sassine.api sqlschema2java-core - 1.0.0-beta1 + 1.0.0-beta sqlschema2java-core Auto generate Class DTO, Entity and Repository from SQL Query. @@ -18,6 +18,19 @@ 0.8.8 Sassine El-Asmar UTF-8 + 4.3 + 1.7.5 + 3.2.0 + 3.10.1 + 2.3.1 + 1.2.11 + 12.47.0 + 1.18.22 + 2.6.6 + 1.9 + 2.13.2 + 2.17.2 + 4.13.2 @@ -64,7 +77,7 @@ org.pitest pitest-maven - 1.7.5 + ${pitest.version} dev.sassine.api.structure.export.* @@ -87,7 +100,7 @@ org.antlr antlr4-maven-plugin - 4.3 + ${antlr4.version} antlr @@ -100,19 +113,19 @@ org.apache.maven.plugins maven-resources-plugin - 2.6 + ${maven-resources.version} - UTF-8 + ${project.build.sourceEncoding} org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + ${maven-compiler} - UTF-8 - 11 - 11 + ${project.build.sourceEncoding} + ${java.version} + ${java.version} @@ -128,7 +141,7 @@ javax.xml.bind jaxb-api - 2.3.1 + ${jax.version} @@ -166,37 +179,36 @@ - org.antlr antlr4-runtime - 4.3 + ${antlr4.version} ch.qos.logback logback-classic - 1.2.11 + ${logback.version} test org.burningwave core - 12.47.0 + ${burningwave.version} org.projectlombok lombok - 1.18.22 + ${lombok.version} org.springframework.boot spring-boot-starter-data-jpa - 2.4.2 + ${spring-jpa.version} org.springframework.boot @@ -236,37 +248,37 @@ org.apache.commons commons-text - 1.9 + ${commons-text.version} com.fasterxml.jackson.core jackson-core - 2.13.2 + ${jackson.version} com.fasterxml.jackson.core jackson-annotations - 2.13.2 + ${jackson.version} com.fasterxml.jackson.core jackson-databind - 2.13.2.2 + ${jackson.version} com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.2 + ${jackson.version} junit junit - 4.13.2 + ${junit-4.version} test @@ -274,13 +286,13 @@ org.apache.logging.log4j log4j-api - 2.17.2 + ${log4j.version} org.apache.logging.log4j log4j-core - 2.17.2 + ${log4j.version} diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java index 7afb8c5..f2b7aa7 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java @@ -1,13 +1,18 @@ package dev.sassine.api.structure; +import static dev.sassine.api.structure.Sqlschema2Java.generate; +import static dev.sassine.api.structure.model.java.EnvironmentModel.builder; +import static java.nio.file.Paths.get; + import java.io.FileNotFoundException; public class Main { public static void main(final String[] args) throws FileNotFoundException { - Sqlschema2Java.generate("C:\\poc\\poc.sql", false, false,"dev.sassine.api.structure.delete"); + generate(builder() + .packageName("dev.sassine.api.structure.generated") + .sourceDirectory(get("src","test","resources","default.sql").toFile().getAbsolutePath()) + .build()); } - -} - +} diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Sqlschema2Java.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Sqlschema2Java.java index b14f5d3..acd0110 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Sqlschema2Java.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Sqlschema2Java.java @@ -14,6 +14,7 @@ import dev.sassine.api.structure.export.builder.ClassSourceBuilder; import dev.sassine.api.structure.model.java.EntityModel; +import dev.sassine.api.structure.model.java.EnvironmentModel; import dev.sassine.api.structure.model.sql.Database; import dev.sassine.api.structure.parser.SqlImport; @@ -21,24 +22,23 @@ public class Sqlschema2Java { private static final Logger log = getLogger(); - public static void generate(String inputFile, boolean isPostgress, boolean isAutoGenerated, String packageName) { - log.debug("preparing to read SQL file('{}') ", inputFile); - try (InputStream in = new FileInputStream(inputFile)) { + public static void generate(EnvironmentModel env) { + log.debug("preparing to read SQL file('{}') ", env.getSourceDirectory()); + try (InputStream in = new FileInputStream(env.getSourceDirectory())) { log.debug("file read successfull"); - log.debug("Parameters ::: isPostgress: {} | isAutoGenerated: {} | packageName: {}", isPostgress, isAutoGenerated, packageName); - process(read(in), isPostgress, isAutoGenerated, packageName); + process(read(in), env); log.info("Congratulations build successful [√]"); } catch (final Exception e) { log.error(e.getMessage(), e); } } - private static void process(final String sqlContent, boolean isPostgress, boolean isAutoGenerated, String packageName) { + private static void process(final String sqlContent, EnvironmentModel env) { final Database database = SqlImport.init().getDatabase(sqlContent); - convertTypeFromSQLDataBaseToEntityStore(database, isPostgress); + convertTypeFromSQLDataBaseToEntityStore(database, env.getUsePostgreSQL()); validate(database); List entityModel = convert(database); - ClassSourceBuilder.init().build(entityModel, isAutoGenerated, packageName); + ClassSourceBuilder.init().build(entityModel, env.getUseAutoIncrement(), env.getPackageName()); } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/ClassSourceBuilder.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/ClassSourceBuilder.java index c2452c1..3350b31 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/ClassSourceBuilder.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/ClassSourceBuilder.java @@ -21,16 +21,17 @@ public static ClassSourceBuilder init() { return new ClassSourceBuilder(); } - public void build(List entityModel, boolean isAutoGenerated, String packageName) { - log.debug("Starting build Class Source"); - entityModel.forEach(e -> build(e, isAutoGenerated, packageName)); + public void build(List entityModel, boolean useAutoGenerated, String packageName) { + log.debug("Starting build Class Source "); + log.debug("Parameters ::: isAutoGenerated: {} | PackageName {}", useAutoGenerated, packageName); + entityModel.forEach(e -> build(e, useAutoGenerated, packageName)); } - private void build(EntityModel entityModel,boolean isAutoGenerated, String packageName) { + private void build(EntityModel entityModel,boolean useAutoGenerated, String packageName) { String nameClass = toCamelCase(entityModel.getName(), true, CHAR); - createEntity().execute(entityModel, isAutoGenerated, nameClass, packageName); - createDTO().execute(entityModel, isAutoGenerated, nameClass, packageName); - createRepository().execute(entityModel, isAutoGenerated, nameClass, packageName); + createEntity().execute(entityModel, useAutoGenerated, nameClass, packageName); + createDTO().execute(entityModel, useAutoGenerated, nameClass, packageName); + createRepository().execute(entityModel, useAutoGenerated, nameClass, packageName); } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EnvironmentModel.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EnvironmentModel.java new file mode 100644 index 0000000..f588a10 --- /dev/null +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EnvironmentModel.java @@ -0,0 +1,22 @@ +package dev.sassine.api.structure.model.java; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Builder +public class EnvironmentModel { + + private String sourceDirectory; + + private String packageName; + + @Builder.Default + private Boolean usePostgreSQL = false; + + @Builder.Default + private Boolean useAutoIncrement = true; + +} diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/type/TypeConverter.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/type/TypeConverter.java index 567e680..436f74d 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/type/TypeConverter.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/type/TypeConverter.java @@ -19,6 +19,7 @@ public class TypeConverter { public static final String TYPE_LOCAL_TIME = "LocalTime"; public static void convertTypeFromSQLDataBaseToEntityStore(final Database database, boolean isPostgress) { + log.debug("Parameters ::: isPostgress: {} ",isPostgress); database.getTables().forEach(table -> { table.getColumnByNames().values().forEach(column -> { column.setConvertedType(convertTypeFromSQLToEntityStore(ofNullable(column.getType()).orElse(""), isPostgress)); diff --git a/sqlschema2java-core/src/test/resources/default.sql b/sqlschema2java-core/src/test/resources/default.sql new file mode 100644 index 0000000..b080153 --- /dev/null +++ b/sqlschema2java-core/src/test/resources/default.sql @@ -0,0 +1,12 @@ +CREATE TABLE Company ( + id INT NOT NULL AUTO_INCREMENT, + duns VARCHAR(9) UNIQUE, + name VARCHAR(255), + address VARCHAR(255), + zip_code VARCHAR(5) DEFAULT '', + company_creation Date DEFAULT CURRENT_TIMESTAMP, + website VARCHAR(255), + phone_number VARCHAR(255), + city VARCHAR(255), + PRIMARY KEY(id) +); \ No newline at end of file diff --git a/sqlschema2java-example/pom.xml b/sqlschema2java-example/pom.xml index d50d9f4..cea626d 100644 --- a/sqlschema2java-example/pom.xml +++ b/sqlschema2java-example/pom.xml @@ -5,7 +5,7 @@ 4.0.0 dev.sasine.api sqlschema2java-example - 1.0.0-beta1 + 1.0.0-beta pom @@ -22,9 +22,10 @@ - false + false false - ./input.sql + ./input.sql + dev.sassine.generated @@ -33,7 +34,7 @@ dev.sassine.api sqlschema2java-maven-plugin - 1.0.0-beta1 + 1.0.0-beta @@ -42,10 +43,10 @@ - ${is.postgres} - ${path.arquivo} + ${use.postgresDB} + ${path.sqlFile} + ${packageName} ${auto.increment.enabled} - false diff --git a/sqlschema2java-maven-plugin/pom.xml b/sqlschema2java-maven-plugin/pom.xml index b45d306..5342e8e 100644 --- a/sqlschema2java-maven-plugin/pom.xml +++ b/sqlschema2java-maven-plugin/pom.xml @@ -6,7 +6,7 @@ 4.0.0 dev.sassine.api sqlschema2java-maven-plugin - 1.0.0-beta1 + 1.0.0-beta sqlschema2java-maven-plugin maven-plugin @@ -23,6 +23,18 @@ + + 1.0.0-beta + 1.8 + 1.8 + 3.6.2 + 3.6.0 + 2.2.1 + 3.6.0 + 3.8.2 + + + dev.sassine.api @@ -80,16 +92,6 @@ - - 1.0.0-beta1 - 1.8 - 1.8 - 3.6.2 - 3.6.0 - 2.2.1 - 3.6.0 - 3.8.2 - diff --git a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java index 89d44e7..a2936a3 100644 --- a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java +++ b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java @@ -10,6 +10,8 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import dev.sassine.api.structure.model.java.EnvironmentModel; + @Mojo(name = "generate", defaultPhase = LifecyclePhase.NONE) public class SqlSchema2Java extends AbstractMojo { @@ -19,19 +21,24 @@ public class SqlSchema2Java extends AbstractMojo { @Parameter(property = "sql.source.directory" , required = true, readonly = true) String sourceDirectory; - @Parameter(property = "sql.source.directory" , defaultValue = "dev.sassine.api.default", required = false, readonly = true) + @Parameter(property = "sql.source.directory" , required = true, readonly = true) String packageName; @Parameter(property = "sql.type.is.postgres" , defaultValue = "false", required = false, readonly = true) - Boolean isPostgres; + Boolean usePostgreSQL; @Parameter(property = "sql.type.auto.increment.enabled" , defaultValue = "true", required = false, readonly = true) Boolean useAutoIncrement; public void execute() throws MojoExecutionException, MojoFailureException { - getLog().info(format(" packageName %s - sourceDirectory %s - isPostgres %s - useAutoIncrement %s", sourceDirectory, packageName, isPostgres, useAutoIncrement)); - generate(sourceDirectory, isPostgres, useAutoIncrement, packageName); + getLog().info(format(" packageName %s - sourceDirectory %s - isPostgres %s - useAutoIncrement %s", sourceDirectory, packageName, usePostgreSQL, useAutoIncrement)); + generate(EnvironmentModel.builder() + .sourceDirectory(sourceDirectory) + .packageName(packageName) + .usePostgreSQL(usePostgreSQL) + .useAutoIncrement(useAutoIncrement) + .build()); } } From 4eec0ba607fa07e16c050f6ff46a8710648ab46d Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Mon, 18 Apr 2022 17:42:11 -0300 Subject: [PATCH 29/43] fix: jackson databind dependency version --- sqlschema2java-core/pom.xml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index fe3fad6..a7d8e83 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -28,7 +28,10 @@ 1.18.22 2.6.6 1.9 - 2.13.2 + 2.13.2 + 2.13.2 + 2.13.2 + 2.13.2.2 2.17.2 4.13.2 @@ -254,25 +257,25 @@ com.fasterxml.jackson.core jackson-core - ${jackson.version} + ${jackson-core.version} com.fasterxml.jackson.core jackson-annotations - ${jackson.version} + ${jackson-annotations.version} com.fasterxml.jackson.core jackson-databind - ${jackson.version} + ${jackson-databind.version} com.fasterxml.jackson.datatype jackson-datatype-jsr310 - ${jackson.version} + ${jackson-datatype.version} From aeb8ecc32645c989441c0a62daa208435ce7fa50 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Mon, 18 Apr 2022 17:50:29 -0300 Subject: [PATCH 30/43] fix: error build static method lombok builder --- .../src/main/java/dev/sassine/api/structure/Main.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java index f2b7aa7..5903f1b 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/Main.java @@ -1,15 +1,16 @@ package dev.sassine.api.structure; import static dev.sassine.api.structure.Sqlschema2Java.generate; -import static dev.sassine.api.structure.model.java.EnvironmentModel.builder; import static java.nio.file.Paths.get; import java.io.FileNotFoundException; +import dev.sassine.api.structure.model.java.EnvironmentModel; + public class Main { public static void main(final String[] args) throws FileNotFoundException { - generate(builder() + generate(EnvironmentModel.builder() .packageName("dev.sassine.api.structure.generated") .sourceDirectory(get("src","test","resources","default.sql").toFile().getAbsolutePath()) .build()); From b686768286f1bb744630ab886618881315576250 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Tue, 19 Apr 2022 21:00:40 -0300 Subject: [PATCH 31/43] fix: example source generated ;) --- .gitignore | 1 - .../default/domain/HistPolicyInfoEntity.java | 66 ++++++++++++++++ .../api/default/dto/HistPolicyInfoDTO.java | 77 +++++++++++++++++++ .../HistPolicyInfoEntityRepository.java | 11 +++ .../delete/domain/HistPolicyInfoEntity.java | 65 ++++++++++++++++ .../delete/dto/HistPolicyInfoDTO.java | 61 +++++++++++++++ .../delete/repository/EntityRepository.java | 11 +++ .../domain/HistPolicyInfoEntity.java | 66 ++++++++++++++++ .../generated/dto/HistPolicyInfoDTO.java | 77 +++++++++++++++++++ .../HistPolicyInfoEntityRepository.java | 11 +++ 10 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/default/domain/HistPolicyInfoEntity.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/default/dto/HistPolicyInfoDTO.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/default/repository/HistPolicyInfoEntityRepository.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/domain/HistPolicyInfoEntity.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/dto/HistPolicyInfoDTO.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/repository/EntityRepository.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/generated/domain/HistPolicyInfoEntity.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/generated/dto/HistPolicyInfoDTO.java create mode 100644 sqlschema2java-example/src/main/java/dev/sassine/generated/repository/HistPolicyInfoEntityRepository.java diff --git a/.gitignore b/.gitignore index b3abc00..e716fa9 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ buildNumber.properties .settings/org.eclipse.m2e.core.prefs .settings/org.springframework.ide.eclipse.prefs sqlschema2java-example/.settings/org.eclipse.m2e.core.prefs -sqlschema2java-example/src sqlschema2java-maven-plugin/.settings/org.eclipse.jdt.core.prefs sqlschema2java-maven-plugin/.settings/org.eclipse.m2e.core.prefs sqlschema2java-maven-plugin/.settings/org.springframework.ide.eclipse.prefs diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/default/domain/HistPolicyInfoEntity.java b/sqlschema2java-example/src/main/java/dev/sassine/api/default/domain/HistPolicyInfoEntity.java new file mode 100644 index 0000000..3010555 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/default/domain/HistPolicyInfoEntity.java @@ -0,0 +1,66 @@ +package dev.sassine.api.default.domain; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@ToString +@Entity +@Table ( + name = "hist_policy_info" +) +public class HistPolicyInfoEntity { + + @Column ( + name = "id", + nullable = false + ) + @Id + private Integer id; + @Column ( + name = "coverage", + nullable = false + ) + private Integer coverage; + @Column ( + name = "sys_end", + nullable = false + ) + private LocalDateTime sysEnd; + @Column ( + name = "policy_id", + nullable = false + ) + private String policyId; + @Column ( + name = "create_id", + nullable = false + ) + private LocalDateTime createId; + @Column ( + name = "bus_end", + nullable = false + ) + private LocalDate busEnd; + @Column ( + name = "bus_start", + nullable = false + ) + private String busStart; + @Column ( + name = "sys_start", + nullable = false + ) + private LocalDateTime sysStart; + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/default/dto/HistPolicyInfoDTO.java b/sqlschema2java-example/src/main/java/dev/sassine/api/default/dto/HistPolicyInfoDTO.java new file mode 100644 index 0000000..53561b9 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/default/dto/HistPolicyInfoDTO.java @@ -0,0 +1,77 @@ +package dev.sassine.api.default.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import dev.sassine.api.default.domain.HistPolicyInfoEntity; +import java.time.LocalDate; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class HistPolicyInfoDTO { + + @JsonProperty ( + value = "id" + ) + private Integer id; + @JsonProperty ( + value = "coverage" + ) + private Integer coverage; + @JsonProperty ( + value = "sys_end" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime sysEnd; + @JsonProperty ( + value = "policy_id" + ) + private String policyId; + @JsonProperty ( + value = "create_id" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime createId; + @JsonProperty ( + value = "bus_end" + ) + @JsonDeserialize ( + using = LocalDateDeserializer.class + ) + private LocalDate busEnd; + @JsonProperty ( + value = "bus_start" + ) + private String busStart; + @JsonProperty ( + value = "sys_start" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime sysStart; + + public HistPolicyInfoEntity toEntity() { + HistPolicyInfoEntity entity = new HistPolicyInfoEntity(); + entity.setId(this.id); + entity.setCoverage(this.coverage); + entity.setSysEnd(this.sysEnd); + entity.setPolicyId(this.policyId); + entity.setCreateId(this.createId); + entity.setBusEnd(this.busEnd); + entity.setBusStart(this.busStart); + entity.setSysStart(this.sysStart); + return entity; + } + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/default/repository/HistPolicyInfoEntityRepository.java b/sqlschema2java-example/src/main/java/dev/sassine/api/default/repository/HistPolicyInfoEntityRepository.java new file mode 100644 index 0000000..9902a1d --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/default/repository/HistPolicyInfoEntityRepository.java @@ -0,0 +1,11 @@ +package dev.sassine.api.default.repository; + +import dev.sassine.api.default.domain.HistPolicyInfoEntity; +import java.lang.Integer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HistPolicyInfoEntityRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/domain/HistPolicyInfoEntity.java b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/domain/HistPolicyInfoEntity.java new file mode 100644 index 0000000..fd89710 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/domain/HistPolicyInfoEntity.java @@ -0,0 +1,65 @@ +package dev.sassine.api.structure.delete.domain; + +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@ToString +@Entity +@Table ( + name = "hist_policy_info" +) +public class HistPolicyInfoEntity { + + @Column ( + name = "id", + nullable = false + ) + @Id + private Integer id; + @Column ( + name = "coverage", + nullable = false + ) + private Integer coverage; + @Column ( + name = "sys_end", + nullable = false + ) + private LocalDateTime sysEnd; + @Column ( + name = "policy_id", + nullable = false + ) + private String policyId; + @Column ( + name = "create_id", + nullable = true + ) + private LocalDateTime createId; + @Column ( + name = "bus_end", + nullable = false + ) + private LocalDateTime busEnd; + @Column ( + name = "bus_start", + nullable = false + ) + private String busStart; + @Column ( + name = "sys_start", + nullable = false + ) + private LocalDateTime sysStart; + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/dto/HistPolicyInfoDTO.java b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/dto/HistPolicyInfoDTO.java new file mode 100644 index 0000000..28cee96 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/dto/HistPolicyInfoDTO.java @@ -0,0 +1,61 @@ +package dev.sassine.api.structure.delete.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import dev.sassine.api.structure.delete.domain.HistPolicyInfoEntity; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class HistPolicyInfoDTO { + + @JsonProperty ( + value = "id" + ) + private Integer id; + @JsonProperty ( + value = "coverage" + ) + private Integer coverage; + @JsonProperty ( + value = "sys_end" + ) + private LocalDateTime sysEnd; + @JsonProperty ( + value = "policy_id" + ) + private String policyId; + @JsonProperty ( + value = "create_id" + ) + private LocalDateTime createId; + @JsonProperty ( + value = "bus_end" + ) + private LocalDateTime busEnd; + @JsonProperty ( + value = "bus_start" + ) + private String busStart; + @JsonProperty ( + value = "sys_start" + ) + private LocalDateTime sysStart; + + public HistPolicyInfoEntity toEntity() { + HistPolicyInfoEntity entity = new HistPolicyInfoEntity(); + this.id = entity.getId(); + this.coverage = entity.getCoverage(); + this.sysEnd = entity.getSysEnd(); + this.policyId = entity.getPolicyId(); + this.createId = entity.getCreateId(); + this.busEnd = entity.getBusEnd(); + this.busStart = entity.getBusStart(); + this.sysStart = entity.getSysStart(); + return entity; + } + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/repository/EntityRepository.java b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/repository/EntityRepository.java new file mode 100644 index 0000000..31d5321 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/api/structure/delete/repository/EntityRepository.java @@ -0,0 +1,11 @@ +package dev.sassine.api.structure.delete.repository; + +import dev.sassine.api.structure.delete.domain.HistPolicyInfoEntity; +import java.lang.Integer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface EntityRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/generated/domain/HistPolicyInfoEntity.java b/sqlschema2java-example/src/main/java/dev/sassine/generated/domain/HistPolicyInfoEntity.java new file mode 100644 index 0000000..15d9cfe --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/generated/domain/HistPolicyInfoEntity.java @@ -0,0 +1,66 @@ +package dev.sassine.generated.domain; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@ToString +@Entity +@Table ( + name = "hist_policy_info" +) +public class HistPolicyInfoEntity { + + @Column ( + name = "id", + nullable = false + ) + @Id + private Integer id; + @Column ( + name = "coverage", + nullable = false + ) + private Integer coverage; + @Column ( + name = "sys_end", + nullable = false + ) + private LocalDateTime sysEnd; + @Column ( + name = "policy_id", + nullable = false + ) + private String policyId; + @Column ( + name = "create_id", + nullable = false + ) + private LocalDateTime createId; + @Column ( + name = "bus_end", + nullable = false + ) + private LocalDate busEnd; + @Column ( + name = "bus_start", + nullable = false + ) + private String busStart; + @Column ( + name = "sys_start", + nullable = false + ) + private LocalDateTime sysStart; + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/generated/dto/HistPolicyInfoDTO.java b/sqlschema2java-example/src/main/java/dev/sassine/generated/dto/HistPolicyInfoDTO.java new file mode 100644 index 0000000..d0f91c3 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/generated/dto/HistPolicyInfoDTO.java @@ -0,0 +1,77 @@ +package dev.sassine.generated.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import dev.sassine.generated.domain.HistPolicyInfoEntity; +import java.time.LocalDate; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class HistPolicyInfoDTO { + + @JsonProperty ( + value = "id" + ) + private Integer id; + @JsonProperty ( + value = "coverage" + ) + private Integer coverage; + @JsonProperty ( + value = "sys_end" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime sysEnd; + @JsonProperty ( + value = "policy_id" + ) + private String policyId; + @JsonProperty ( + value = "create_id" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime createId; + @JsonProperty ( + value = "bus_end" + ) + @JsonDeserialize ( + using = LocalDateDeserializer.class + ) + private LocalDate busEnd; + @JsonProperty ( + value = "bus_start" + ) + private String busStart; + @JsonProperty ( + value = "sys_start" + ) + @JsonDeserialize ( + using = LocalDateTimeDeserializer.class + ) + private LocalDateTime sysStart; + + public HistPolicyInfoEntity toEntity() { + HistPolicyInfoEntity entity = new HistPolicyInfoEntity(); + entity.setId(this.id); + entity.setCoverage(this.coverage); + entity.setSysEnd(this.sysEnd); + entity.setPolicyId(this.policyId); + entity.setCreateId(this.createId); + entity.setBusEnd(this.busEnd); + entity.setBusStart(this.busStart); + entity.setSysStart(this.sysStart); + return entity; + } + +} \ No newline at end of file diff --git a/sqlschema2java-example/src/main/java/dev/sassine/generated/repository/HistPolicyInfoEntityRepository.java b/sqlschema2java-example/src/main/java/dev/sassine/generated/repository/HistPolicyInfoEntityRepository.java new file mode 100644 index 0000000..6bba8a9 --- /dev/null +++ b/sqlschema2java-example/src/main/java/dev/sassine/generated/repository/HistPolicyInfoEntityRepository.java @@ -0,0 +1,11 @@ +package dev.sassine.generated.repository; + +import dev.sassine.generated.domain.HistPolicyInfoEntity; +import java.lang.Integer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HistPolicyInfoEntityRepository extends JpaRepository { + +} \ No newline at end of file From cc368afb78d8f837a3dbc6bbcf2aefd2ef75352d Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Thu, 21 Apr 2022 16:35:58 -0300 Subject: [PATCH 32/43] Feature: Implements deploy distribuition maven central \ sonatype --- .github/workflows/deploy.yml | 52 +++--------- sqlschema2java-core/pom.xml | 120 ++++++++++++++++++++++++--- sqlschema2java-example/pom.xml | 8 +- sqlschema2java-maven-plugin/pom.xml | 124 ++++++++++++++++++++++++---- 4 files changed, 229 insertions(+), 75 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6b04c8b..47faa8b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,52 +1,22 @@ -name: Publish package to GitHub Packages +name: Publish package Sonatype - Maven Central on: release: types: [created] jobs: - publish-core: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - - name: Publish package SQLSchema2Java Core - run: | - cd sqlschema2java-core - mvn --batch-mode deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - deploy-await: + deploy-core: runs-on: ubuntu-latest - needs: publish-core steps: - - name: Sleep for 5 minutes + - name: Sleep for 30 minutes uses: jakejarvis/wait-action@master with: - time: '5m' - - publish-maven-plugin: - runs-on: ubuntu-latest + time: '30m' + deploy-plugin: + runs-on: ubuntu-latest environment: name: plugin - permissions: - contents: read - packages: write - needs: deploy-await + needs: deploy-core steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - - name: Publish package SQLSchema2Java MavenPLugin - run: | - cd sqlschema2java-maven-plugin - mvn --batch-mode deploy - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Sleep for 30 minutes + uses: jakejarvis/wait-action@master + with: + time: '30m' \ No newline at end of file diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index a7d8e83..69fc56d 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -10,7 +10,37 @@ sqlschema2java-core Auto generate Class DTO, Entity and Repository from SQL Query. - https://sassine.dev/ + https://github.com/Sassine/sqlschema2java + + + + MIT License + https://github.com/Sassine/sqlschema2java/blob/master/LICENSE + repo + + + + + github.com + https://github.com/Sassine/sqlschema2java/issues + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + scm:git:git://github.com/Sassine/sqlschema2java.git + scm:git:ssh://github.com:Sassine/sqlschema2java.git + https://github.com/Sassine/sqlschema2java/tree/main + 11 @@ -22,6 +52,8 @@ 1.7.5 3.2.0 3.10.1 + 11 + 11 2.3.1 1.2.11 12.47.0 @@ -34,6 +66,10 @@ 2.13.2.2 2.17.2 4.13.2 + 1.6.7 + 2.2.1 + 2.9.1 + 1.5 @@ -76,7 +112,32 @@ ${project.basedir}/src/test/resources + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${sonatype-nexus.version} + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source.version} + + + attach-sources + + jar-no-fork + + + + org.pitest pitest-maven @@ -127,8 +188,8 @@ ${maven-compiler} ${project.build.sourceEncoding} - ${java.version} - ${java.version} + ${maven.compiler.source} + ${maven.compiler.target} @@ -179,8 +240,54 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + + false + **/*SqlListener*,**/*SqlBaseListener*,**/*SqlLexer*,**/*SqlParser*,**/*Main* + + 2.9.1 + + + attach-javadocs + + jar + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + @@ -301,12 +408,5 @@ - - - github - GitHub Packages - https://maven.pkg.github.com/Sassine/sqlschema2java - - diff --git a/sqlschema2java-example/pom.xml b/sqlschema2java-example/pom.xml index cea626d..90f7381 100644 --- a/sqlschema2java-example/pom.xml +++ b/sqlschema2java-example/pom.xml @@ -52,12 +52,6 @@ - - - github - GitHub Packages SQLSchema2Java - https://maven.pkg.github.com/Sassine/sqlschema2java - - + \ No newline at end of file diff --git a/sqlschema2java-maven-plugin/pom.xml b/sqlschema2java-maven-plugin/pom.xml index 5342e8e..5f60846 100644 --- a/sqlschema2java-maven-plugin/pom.xml +++ b/sqlschema2java-maven-plugin/pom.xml @@ -10,6 +10,39 @@ sqlschema2java-maven-plugin maven-plugin + Plugin auto generate Class DTO, Entity and Repository from SQL Query. + https://github.com/Sassine/sqlschema2java + + + + MIT License + https://github.com/Sassine/sqlschema2java/blob/master/LICENSE + repo + + + + + github.com + https://github.com/Sassine/sqlschema2java/issues + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + scm:git:git://github.com/Sassine/sqlschema2java.git + scm:git:ssh://github.com:Sassine/sqlschema2java.git + https://github.com/Sassine/sqlschema2java/tree/main + + Sassine El-Asmar @@ -32,6 +65,10 @@ 2.2.1 3.6.0 3.8.2 + 1.6.7 + 2.2.1 + 2.9.1 + 1.5 @@ -62,6 +99,30 @@ + + org.sonatype.plugins + nexus-staging-maven-plugin + ${sonatype-nexus.version} + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source.version} + + + attach-sources + + jar-no-fork + + + + org.apache.maven.plugins maven-plugin-plugin @@ -72,10 +133,56 @@ maven-site-plugin ${maven-site-plugin.version} + + org.apache.maven.plugins + maven-javadoc-plugin + + false + + 2.9.1 + + + attach-javadocs + + jar + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + @@ -92,21 +199,4 @@ - - - - github - GitHub Packages - https://maven.pkg.github.com/Sassine/sqlschema2java - - - - - - github - GitHub Packages SQLSchema2Java - https://maven.pkg.github.com/Sassine/sqlschema2java - - - \ No newline at end of file From 8c32865bbc9e34de021230cb38e03fc1e96a845c Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Thu, 21 Apr 2022 17:46:58 -0300 Subject: [PATCH 33/43] refactor: String formatted, remove constants String format --- .../builder/factory/impl/DTOFactory.java | 22 ++++------- .../builder/factory/impl/EntityFactory.java | 18 ++++----- .../builder/function/ImportBeanFunction.java | 39 ++++++++++--------- .../api/structure/model/java/EntityModel.java | 2 +- .../api/structure/model/sql/Database.java | 2 +- .../api/structure/model/sql/ForeignKey.java | 4 +- .../api/structure/model/sql/PrimaryKey.java | 2 +- .../api/structure/model/sql/TableModel.java | 4 +- .../parser/CreateTableParseListener.java | 24 ++++++------ .../api/structure/parser/GetSqlQuery.java | 2 +- .../maven/plugin/start/SqlSchema2Java.java | 3 +- 11 files changed, 57 insertions(+), 65 deletions(-) diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java index 9320a38..2fb2994 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/DTOFactory.java @@ -3,7 +3,6 @@ import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importEntityClass; import static dev.sassine.api.structure.export.builder.function.ImportBeanFunction.importJavaTimeAndJSONDeserialize; import static dev.sassine.api.structure.export.builder.function.StoreClassFuncation.store; -import static java.lang.String.format; import static java.lang.reflect.Modifier.PUBLIC; import static org.apache.logging.log4j.LogManager.getLogger; @@ -33,12 +32,6 @@ public class DTOFactory implements Factory { private static final String PACKAGE_DTO_NAME = "dto"; private static final String METHOD_TO_ENTITY = "toEntity"; private static final String METHOD_RETURN_ENTITY = "return entity;"; - private static final String FORMAT_DTO_CLASSNAME = "%sDTO"; - private static final String FORMAT_ENTITY_CLASSNAME = "%sEntity"; - private static final String FORMAT_NEW_ENTITY_METHOD = "%s entity = new %s();"; - private static final String FORMAT_STRING_FIELDS = "\"%s\""; - private static final String FORMAT_PACKAGE_DOT_PACKAGE = "%s.%s"; - private static final String FORMAT_SET_VALUE = "entity.set%s(this.%s);"; private static final String PARAM_VALUE = "value"; @Override @@ -49,9 +42,7 @@ public void execute(EntityModel entityModel,boolean isAutoGenerated, String name ClassSourceGenerator clDTO = this.buildClassSource(nameClass); log.debug("ClassDTO builded"); importEntityClass(nameClass, packageName, gen); - String nameEntityClass = format(FORMAT_ENTITY_CLASSNAME, nameClass); - log.debug("Prepared EntityClassName ({})",nameEntityClass); - FunctionSourceGenerator fm = this.startFunctionMethod(nameEntityClass); + FunctionSourceGenerator fm = this.startFunctionMethod("%sEntity".formatted(nameClass)); log.debug("Started functionMethod toEntity"); log.debug("Prepare generate ({}) fields", entityModel.getFields().size()); entityModel.getFields().forEach(fieldModel -> { @@ -76,7 +67,7 @@ private void closeMethodFunction(FunctionSourceGenerator functionMethodToEntity) } private void addFunctionToMethodFunction(FunctionSourceGenerator functionMethodToEntity, FieldModel fieldModel) { - functionMethodToEntity.addBodyCodeLine(format(FORMAT_SET_VALUE, fieldModel.getCamelNameUpper(), fieldModel.getCamelName())); + functionMethodToEntity.addBodyCodeLine("entity.set%s(this.%s);".formatted(fieldModel.getCamelNameUpper(), fieldModel.getCamelName())); } private VariableSourceGenerator buildField(FieldModel fieldModel) { @@ -84,26 +75,27 @@ private VariableSourceGenerator buildField(FieldModel fieldModel) { .create(TypeDeclarationSourceGenerator.create(fieldModel.getType()), fieldModel.getCamelName()) .addModifier(Modifier.PRIVATE) .addAnnotation(AnnotationSourceGenerator.create(JsonProperty.class) - .addParameter(PARAM_VALUE,VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, fieldModel.getName())))); + .addParameter(PARAM_VALUE,VariableSourceGenerator.create("\"%s\"".formatted(fieldModel.getName())))); } private FunctionSourceGenerator startFunctionMethod(String nameEntityClass) { + log.debug("Prepared EntityClassName ({})",nameEntityClass); return FunctionSourceGenerator .create(METHOD_TO_ENTITY) .addModifier(PUBLIC).setReturnType(nameEntityClass) - .addBodyCodeLine(format(FORMAT_NEW_ENTITY_METHOD, nameEntityClass, nameEntityClass)); + .addBodyCodeLine("%s entity = new %s();".formatted(nameEntityClass, nameEntityClass)); } private ClassSourceGenerator buildClassSource(String nameClass) { return ClassSourceGenerator - .create(TypeDeclarationSourceGenerator.create(format(FORMAT_DTO_CLASSNAME, nameClass))) + .create(TypeDeclarationSourceGenerator.create("%sDTO".formatted(nameClass))) .addModifier(PUBLIC).addAnnotation(AnnotationSourceGenerator.create(Getter.class)) .addAnnotation(AnnotationSourceGenerator.create(Setter.class)) .addAnnotation(AnnotationSourceGenerator.create(NoArgsConstructor.class)); } private UnitSourceGenerator buildPackage(String packageName) { - return UnitSourceGenerator.create(format(FORMAT_PACKAGE_DOT_PACKAGE, packageName, PACKAGE_DTO_NAME)); + return UnitSourceGenerator.create("%s.%s".formatted(packageName, PACKAGE_DTO_NAME)); } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java index e75b309..9b1ce4e 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/factory/impl/EntityFactory.java @@ -5,7 +5,6 @@ import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE; import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE_TIME; import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_TIME; -import static java.lang.String.format; import static java.lang.reflect.Modifier.PRIVATE; import static java.lang.reflect.Modifier.PUBLIC; import static java.util.Objects.nonNull; @@ -42,9 +41,6 @@ public class EntityFactory implements Factory { private static final Logger log = getLogger(); private static final String PACKAGE_DOMAIN_NAME = "domain"; - private static final String FORMAT_ENTITY_CLASSNAME = "%sEntity"; - private static final String FORMAT_STRING_FIELDS = "\"%s\""; - private static final String FORMAT_PACKAGE_DOT_PACKAGE = "%s.%s"; private static final String PARAM_NULLABLE = "nullable"; private static final String PARAM_NAME = "name"; @@ -80,24 +76,24 @@ private void setDefaultValue(VariableSourceGenerator field, FieldModel fieldMode var value = defaultValueLocal.get(fieldModel.getType()); if(nonNull(value)) field.setValue(defaultValueLocal.get(fieldModel.getType())); field.addAnnotation(AnnotationSourceGenerator.create(ColumnDefault.class).addParameter("value", - VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, fieldModel.getDefaultValue())))); + VariableSourceGenerator.create(stringMarks(fieldModel.getDefaultValue())))); } } private ClassSourceGenerator buildClassSource(EntityModel entityModel, String nameClass) { return ClassSourceGenerator - .create(TypeDeclarationSourceGenerator.create(format(FORMAT_ENTITY_CLASSNAME, nameClass))) + .create(TypeDeclarationSourceGenerator.create("%sEntity".formatted(nameClass))) .addModifier(PUBLIC).addAnnotation(AnnotationSourceGenerator.create(Getter.class)) .addAnnotation(AnnotationSourceGenerator.create(Setter.class)) .addAnnotation(AnnotationSourceGenerator.create(NoArgsConstructor.class)) .addAnnotation(AnnotationSourceGenerator.create(ToString.class)) .addAnnotation(AnnotationSourceGenerator.create(Entity.class)) .addAnnotation(AnnotationSourceGenerator.create(Table.class) - .addParameter(PARAM_NAME,VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, entityModel.getName())))); + .addParameter(PARAM_NAME,VariableSourceGenerator.create(stringMarks(entityModel.getName())))); } private UnitSourceGenerator buildPackage(String packageName) { - return UnitSourceGenerator.create(format(FORMAT_PACKAGE_DOT_PACKAGE, packageName, PACKAGE_DOMAIN_NAME)); + return UnitSourceGenerator.create("%s.%s".formatted(packageName, PACKAGE_DOMAIN_NAME)); } private VariableSourceGenerator buildField(FieldModel fieldModel) { @@ -105,7 +101,7 @@ private VariableSourceGenerator buildField(FieldModel fieldModel) { .create(TypeDeclarationSourceGenerator.create(fieldModel.getType()), fieldModel.getCamelName()) .addModifier(PRIVATE) .addAnnotation(AnnotationSourceGenerator.create(Column.class) - .addParameter(PARAM_NAME,VariableSourceGenerator.create(format(FORMAT_STRING_FIELDS, fieldModel.getName()))) + .addParameter(PARAM_NAME,VariableSourceGenerator.create(stringMarks(fieldModel.getName()))) .addParameter(PARAM_NULLABLE,VariableSourceGenerator.create(String.valueOf(fieldModel.getNullable())))); } @@ -116,5 +112,9 @@ private void generateEntityPK(boolean isAutoGenerated, FieldModel fieldModel, Va if (isAutoGenerated) field.addAnnotation(AnnotationSourceGenerator.create(GeneratedValue.class)); } } + + private String stringMarks(String value) { + return "\"%s\"".formatted(value); + } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java index 042d043..9f6d82f 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/export/builder/function/ImportBeanFunction.java @@ -3,14 +3,12 @@ import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE; import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_DATE_TIME; import static dev.sassine.api.structure.type.TypeConverter.TYPE_LOCAL_TIME; -import static java.lang.String.format; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import org.burningwave.core.classes.AnnotationSourceGenerator; -import org.burningwave.core.classes.TypeDeclarationSourceGenerator; import org.burningwave.core.classes.UnitSourceGenerator; import org.burningwave.core.classes.VariableSourceGenerator; @@ -22,40 +20,45 @@ import dev.sassine.api.structure.model.java.FieldModel; public class ImportBeanFunction { - + private static final String TIME_DESERIALIZER = "LocalTimeDeserializer.class"; private static final String DATE_DESERIALIZER = "LocalDateDeserializer.class"; private static final String DATE_TIME_DESERIALIZER = "LocalDateTimeDeserializer.class"; private static final String PARAM_USING = "using"; - private static final String FORMAT_IMPORT_ENTITY_PACKAGE = "%s.domain.%sEntity"; - + public static void importEntityClass(String nameClass, String packageName, UnitSourceGenerator gen) { - gen.addImport(format(FORMAT_IMPORT_ENTITY_PACKAGE, packageName, nameClass)); + gen.addImport("%s.domain.%sEntity".formatted(packageName, nameClass)); } public static void importJavaTime(UnitSourceGenerator gen, FieldModel fieldModel) { - if (TYPE_LOCAL_DATE_TIME.equals(fieldModel.getType())) gen.addImport(LocalDateTime.class); - else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) gen.addImport(LocalDate.class); - else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) gen.addImport(LocalTime.class); + if (TYPE_LOCAL_DATE_TIME.equals(fieldModel.getType())) + gen.addImport(LocalDateTime.class); + else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) + gen.addImport(LocalDate.class); + else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) + gen.addImport(LocalTime.class); } public static void importJavaTimeAndJSONDeserialize(VariableSourceGenerator field, UnitSourceGenerator gen, FieldModel fieldModel) { if (TYPE_LOCAL_DATE_TIME.equals(fieldModel.getType())) { gen.addImport(LocalDateTime.class); - gen.addImport(LocalDateTimeDeserializer.class); - field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(DATE_TIME_DESERIALIZER)))); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class) + .addParameter(VariableSourceGenerator.create(PARAM_USING). + setValue(DATE_TIME_DESERIALIZER) + .useType(LocalDateTimeDeserializer.class))); } else if (TYPE_LOCAL_DATE.equals(fieldModel.getType())) { gen.addImport(LocalDate.class); - gen.addImport(LocalDateDeserializer.class); - field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(DATE_DESERIALIZER)))); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class) + .addParameter(VariableSourceGenerator.create(PARAM_USING) + .setValue(DATE_DESERIALIZER) + .useType(LocalDateDeserializer.class))); } else if (TYPE_LOCAL_TIME.equals(fieldModel.getType())) { gen.addImport(LocalTime.class); - gen.addImport(LocalTimeDeserializer.class); - field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class).addParameter(PARAM_USING, - VariableSourceGenerator.create(TypeDeclarationSourceGenerator.create(TIME_DESERIALIZER)))); + field.addAnnotation(AnnotationSourceGenerator.create(JsonDeserialize.class) + .addParameter(VariableSourceGenerator.create(PARAM_USING) + .setValue(TIME_DESERIALIZER) + .useType(LocalTimeDeserializer.class))); } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EntityModel.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EntityModel.java index fd86829..6daf6f9 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EntityModel.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/java/EntityModel.java @@ -14,7 +14,7 @@ public class EntityModel { private String pkPolicy; private String pkType; - private List fields = new ArrayList(); + private List fields = new ArrayList<>(); public FieldModel getFieldForName(final String name) { return fields.stream().filter(field -> field.getName().equalsIgnoreCase(name)).findFirst().orElse(null); diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/Database.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/Database.java index 5da0352..30a7339 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/Database.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/Database.java @@ -10,7 +10,7 @@ @Setter public class Database { - private List tables = new ArrayList(); + private List tables = new ArrayList<>(); public TableModel getTableForName(final String tableName) { return tables.stream().filter(table -> table.getName().equalsIgnoreCase(tableName)).findAny().orElse(null); diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/ForeignKey.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/ForeignKey.java index dc600d0..9729955 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/ForeignKey.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/ForeignKey.java @@ -10,8 +10,8 @@ @Setter public class ForeignKey { - private List columnNameOrigins = new ArrayList(); - private List columnNameTargets = new ArrayList(); + private List columnNameOrigins = new ArrayList<>(); + private List columnNameTargets = new ArrayList<>(); private String tableNameOrigin; private String tableNameTarget; diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/PrimaryKey.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/PrimaryKey.java index 1b69601..180ea4d 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/PrimaryKey.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/PrimaryKey.java @@ -8,6 +8,6 @@ @Getter public class PrimaryKey { - List columnNames = new ArrayList(); + List columnNames = new ArrayList<>(); } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/TableModel.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/TableModel.java index a0c9d2a..df5278c 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/TableModel.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/model/sql/TableModel.java @@ -13,9 +13,9 @@ public class TableModel { private String name; - private Map columnByNames = new HashMap(); + private Map columnByNames = new HashMap<>(); private PrimaryKey primaryKey = new PrimaryKey(); - private List foreignKeys = new ArrayList(); + private List foreignKeys = new ArrayList<>(); public ForeignKey getForeignKeyForColumnNameOrigin(final Column column) { for (ForeignKey fk : foreignKeys) { diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/CreateTableParseListener.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/CreateTableParseListener.java index 1cb341b..ab80e6c 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/CreateTableParseListener.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/CreateTableParseListener.java @@ -1,6 +1,6 @@ package dev.sassine.api.structure.parser; -import static java.lang.String.format; +import static dev.sassine.api.structure.util.Util.unformatSqlName; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -29,12 +29,10 @@ import dev.sassine.api.structure.model.sql.Database; import dev.sassine.api.structure.model.sql.ForeignKey; import dev.sassine.api.structure.model.sql.TableModel; -import dev.sassine.api.structure.util.Util; public class CreateTableParseListener extends SqlBaseListener { private static final Logger log = LogManager.getLogger(); private static final String AUTOINCREMENT = "AUTOINCREMENT"; - private static final String FORMAT_COLUMN_TYPE = "%s %s"; private final SqlParser sqlParser; private final Database database; @@ -78,7 +76,7 @@ public void exitCreate_table_stmt(final Create_table_stmtContext ctx) { @Override public void exitTable_name(final Table_nameContext ctx) { if (inCreateTable) { - table.setName(Util.unformatSqlName(ctx.getText())); + table.setName(unformatSqlName(ctx.getText())); } } @@ -104,7 +102,7 @@ public void exitColumn_def(final Column_defContext ctx) { @Override public void exitColumn_name(final Column_nameContext ctx) { if (inCreateTable && inColumnDef) { - column.setName(Util.unformatSqlName(ctx.getText())); + column.setName(unformatSqlName(ctx.getText())); } } @@ -122,10 +120,10 @@ public void exitType_name(final Type_nameContext ctx) { public void exitName(final NameContext ctx) { if (inCreateTable && inColumnDef && inTypeName) { if (column.getType() == null) { - column.setType(Util.unformatSqlName(ctx.getText())); + column.setType(unformatSqlName(ctx.getText())); } else { - String ctxType = !ctx.getText().replace("_", "").equals(AUTOINCREMENT) ? Util.unformatSqlName(ctx.getText()) : ""; - column.setType(format(FORMAT_COLUMN_TYPE, column.getType(), ctxType)); + String ctxType = !ctx.getText().replace("_", "").equals(AUTOINCREMENT) ? unformatSqlName(ctx.getText()) : ""; + column.setType("%s %s".formatted(column.getType(), ctxType)); } } } @@ -133,7 +131,7 @@ public void exitName(final NameContext ctx) { @Override public void exitColumn_default_value(final Column_default_valueContext ctx) { if (inCreateTable && inColumnDef) { - column.setDefaultValue(Util.unformatSqlName(ctx.getText())); + column.setDefaultValue(unformatSqlName(ctx.getText())); } } @@ -164,7 +162,7 @@ public void exitTable_constraint_primary_key(final Table_constraint_primary_keyC @Override public void exitIndexed_column(final Indexed_columnContext ctx) { if (inCreateTable && inTable_constraint_primary_key) { - final String columnName = Util.unformatSqlName(ctx.getText()); + final String columnName = unformatSqlName(ctx.getText()); table.getPrimaryKey().getColumnNames().add(columnName); } } @@ -207,21 +205,21 @@ public void exitForeign_key_clause(final Foreign_key_clauseContext ctx) { @Override public void exitForeign_table(final Foreign_tableContext ctx) { if (inCreateTable) { - foreignKey.setTableNameTarget(Util.unformatSqlName(ctx.getText())); + foreignKey.setTableNameTarget(unformatSqlName(ctx.getText())); } } @Override public void exitFk_origin_column_name(final Fk_origin_column_nameContext ctx) { if (foreignKey != null) { - foreignKey.getColumnNameOrigins().add(Util.unformatSqlName(ctx.getText())); + foreignKey.getColumnNameOrigins().add(unformatSqlName(ctx.getText())); } } @Override public void exitFk_target_column_name(final Fk_target_column_nameContext ctx) { if (inCreateTable) { - foreignKey.getColumnNameTargets().add(Util.unformatSqlName(ctx.getText())); + foreignKey.getColumnNameTargets().add(unformatSqlName(ctx.getText())); } } diff --git a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/GetSqlQuery.java b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/GetSqlQuery.java index 05fa4c7..7e592dd 100644 --- a/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/GetSqlQuery.java +++ b/sqlschema2java-core/src/main/java/dev/sassine/api/structure/parser/GetSqlQuery.java @@ -27,7 +27,7 @@ else if(queryUpperCase.indexOf(ALTER_TABLE) == 0) { } public List getSqlQuerys(final String content) { - final List querys = new ArrayList(); + final List querys = new ArrayList<>(); int posStart = getPosStartQuery(content, 0); int posEnd = getPosEndQuery(content, posStart); diff --git a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java index a2936a3..c9c69f5 100644 --- a/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java +++ b/sqlschema2java-maven-plugin/src/main/java/dev/sassine/api/maven/plugin/start/SqlSchema2Java.java @@ -1,6 +1,5 @@ package dev.sassine.api.maven.plugin.start; import static dev.sassine.api.structure.Sqlschema2Java.generate; -import static java.lang.String.format; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -32,7 +31,7 @@ public class SqlSchema2Java extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { - getLog().info(format(" packageName %s - sourceDirectory %s - isPostgres %s - useAutoIncrement %s", sourceDirectory, packageName, usePostgreSQL, useAutoIncrement)); + getLog().info(" packageName %s - sourceDirectory %s - isPostgres %s - useAutoIncrement %s".formatted(sourceDirectory, packageName, usePostgreSQL, useAutoIncrement)); generate(EnvironmentModel.builder() .sourceDirectory(sourceDirectory) .packageName(packageName) From f2e30e1521e2d395b46c22fa840a5f902118b364 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Thu, 21 Apr 2022 19:05:07 -0300 Subject: [PATCH 34/43] fix: Deploy version --- .github/workflows/codeql-analysis.yml | 10 ++++++++-- .github/workflows/compute-covarage.yml | 2 +- README.md | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ca5af78..30f6458 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL main" on: push: - branches: [ main ] + branches: [ main, develop ] pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: [ main, develop ] jobs: analyze: @@ -38,6 +38,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: Set JDK Version + - uses: actions/setup-java@v3 + with: + java-version: '16' + distribution: 'adopt' + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 diff --git a/.github/workflows/compute-covarage.yml b/.github/workflows/compute-covarage.yml index 4cc9aab..ffc56f6 100644 --- a/.github/workflows/compute-covarage.yml +++ b/.github/workflows/compute-covarage.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '16' distribution: 'adopt' - name: Build and test run: cd sqlschema2java-core && mvn clean test jacoco:report coveralls:report -DrepoToken=${{ secrets.coveralls_repo_token }} diff --git a/README.md b/README.md index 59f1f42..ed8ed91 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # SQLSchema2Java [![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) -[![Publish package to GitHub Packages](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/deploy.yml) +[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=main)](https://coveralls.io/github/Sassine/sqlschema2java?branch=main) [![CodeQL main](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Sassine/sqlschema2java/actions/workflows/codeql-analysis.yml) -[![GitHub release](https://img.shields.io/github/release/Sassine/sqlschema2java.svg)](https://GitHub.com/Sassine/sqlschema2java/releases/) -[![Coverage Status](https://coveralls.io/repos/github/Sassine/sqlschema2java/badge.svg?branch=main)](https://coveralls.io/github/Sassine/sqlschema2java?branch=main) +![Maven Central](https://img.shields.io/maven-central/v/dev.sassine.api/sqlschema2java-core?color=purple&label=SQLSchema2java%20-%20Core&logo=java&logoColor=red&style=flat-square) +![Maven Central](https://img.shields.io/maven-central/v/dev.sassine.api/sqlschema2java-maven-plugin?color=purple&label=SQLSchema2java%20-%20Maven-Plugin&logo=java&logoColor=red&style=flat-square) + ![Logo SQL2JAVA and website adress sassine.dev/sqlschema2java](https://sassine.dev/assets/images/SQLSchema2Java_Logo2.png) From ad48aadfd0db3fe7ee0483f0b7ddfaebda9ebb13 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Thu, 21 Apr 2022 19:09:33 -0300 Subject: [PATCH 35/43] fix: Deploy version --- .github/workflows/codeql-analysis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 30f6458..6845ece 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,10 +39,10 @@ jobs: uses: actions/checkout@v3 - name: Set JDK Version - - uses: actions/setup-java@v3 - with: - java-version: '16' - distribution: 'adopt' + uses: actions/setup-java@v3 + with: + java-version: '16' + distribution: 'adopt' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From 5e9b741ff48e2fe0e05e8da2d40e28c327f20530 Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 23 Apr 2022 23:06:36 -0300 Subject: [PATCH 36/43] Removing repository github --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ed8ed91..617f43d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ pom.xml dev.sassine.api sqlschema2java-maven-plugin - 1.0.0 + 1.0.0-beta @@ -48,13 +48,7 @@ pom.xml - - - github - GitHub Packages SQLSchema2Java - https://maven.pkg.github.com/Sassine/sqlschema2java - - + ``` ### Parameters | Name | required | type | description | From 5cdb4367368987323fe9f3424770b3d88a955b2a Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 23 Apr 2022 23:07:51 -0300 Subject: [PATCH 37/43] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 617f43d..e65d110 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ pom.xml - /user/home/example.sql + ./example.sql dev.sassine.api true - false + false @@ -56,7 +56,7 @@ pom.xml | sourceDirectory | true | String | SQL file path | | packageName | true | String | package name with points that will be generated | | useAutoIncrement| false | Boolean| disable or enable whether the primary key will have its value generated automatically | -| isPostgres| true | Boolean | disable or enable query conversion compatible with postgres database | +| usePostgreSQL | true | Boolean | disable or enable query conversion compatible with postgres database | ##### Run command From 228da804f9bc2317343978f64289be7dc913f00c Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Sat, 23 Apr 2022 23:08:31 -0300 Subject: [PATCH 38/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e65d110..4e7416b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ pom.xml ./example.sql dev.sassine.api true - false + false From 4cc01bac91256f0f46d3cfe7a558d80bdbf40a9d Mon Sep 17 00:00:00 2001 From: Sassine El-Asmar Date: Fri, 6 May 2022 11:48:51 -0300 Subject: [PATCH 39/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e7416b..fedacf3 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ pom.xml - sqlschema2java + generate From ed8b6ffa215fd9d367044e44613db62f9007d9d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 18:00:23 +0000 Subject: [PATCH 40/43] build(deps): bump jackson-databind in /sqlschema2java-core Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.2.2 to 2.13.4.1. - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- sqlschema2java-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 69fc56d..a434e63 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -63,7 +63,7 @@ 2.13.2 2.13.2 2.13.2 - 2.13.2.2 + 2.13.4.1 2.17.2 4.13.2 1.6.7 From 286bf151514cb347389a60c1abdc2e66860b1fad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 18:02:58 +0000 Subject: [PATCH 41/43] build(deps): bump commons-text in /sqlschema2java-core Bumps commons-text from 1.9 to 1.10.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-text dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- sqlschema2java-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 69fc56d..e7c1da8 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -59,7 +59,7 @@ 12.47.0 1.18.22 2.6.6 - 1.9 + 1.10.0 2.13.2 2.13.2 2.13.2 From 79c6afec57074377ddef65d9ac7e3c831d52c8a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:22:21 +0000 Subject: [PATCH 42/43] build(deps): bump jackson-databind in /sqlschema2java-core Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.4.1 to 2.13.4.2. - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- sqlschema2java-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index c3ea5a8..7eb30c3 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -63,7 +63,7 @@ 2.13.2 2.13.2 2.13.2 - 2.13.4.1 + 2.13.4.2 2.17.2 4.13.2 1.6.7 From 8731e87f331e6af83d340e61a198716cf8f2288d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:45:12 +0000 Subject: [PATCH 43/43] build(deps-dev): bump ch.qos.logback:logback-classic Bumps [ch.qos.logback:logback-classic](https://github.com/qos-ch/logback) from 1.2.11 to 1.3.12. - [Commits](https://github.com/qos-ch/logback/compare/v_1.2.11...v_1.3.12) --- updated-dependencies: - dependency-name: ch.qos.logback:logback-classic dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- sqlschema2java-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlschema2java-core/pom.xml b/sqlschema2java-core/pom.xml index 7eb30c3..9a6155a 100644 --- a/sqlschema2java-core/pom.xml +++ b/sqlschema2java-core/pom.xml @@ -55,7 +55,7 @@ 11 11 2.3.1 - 1.2.11 + 1.3.12 12.47.0 1.18.22 2.6.6