From cb9e16dbf37295fbc1d32b8d378d7e27f5104bd2 Mon Sep 17 00:00:00 2001 From: "CORP\\leholm" Date: Fri, 12 Aug 2022 14:08:46 +0200 Subject: [PATCH] #860 template structure and sql util class --- .../cobigen-eclipse-test/.classpath | 4 +-- cobigen-templates/sql-openapi-app/context.xml | 13 ++++++++++ .../sql-openapi-app/templates.xml | 0 .../templates/devon4j/utils/SQLUtil.java | 25 +++++++++++++++++++ .../main/templates/sql_java_app/context.xml | 13 ++++++++++ .../main/templates/sql_java_app/templates.xml | 21 ++++++++++++++++ .../${variables.entityName}Entity.sql.ftl | 23 +++++++++++++++++ 7 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 cobigen-templates/sql-openapi-app/context.xml create mode 100644 cobigen-templates/sql-openapi-app/templates.xml create mode 100644 cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java create mode 100644 cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/context.xml create mode 100644 cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates.xml create mode 100644 cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/${variables.entityName}Entity.sql.ftl diff --git a/cobigen-eclipse/cobigen-eclipse-test/.classpath b/cobigen-eclipse/cobigen-eclipse-test/.classpath index 8d0ae98bfc..831f611b54 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/.classpath +++ b/cobigen-eclipse/cobigen-eclipse-test/.classpath @@ -1,7 +1,5 @@ - - @@ -32,5 +30,7 @@ + + diff --git a/cobigen-templates/sql-openapi-app/context.xml b/cobigen-templates/sql-openapi-app/context.xml new file mode 100644 index 0000000000..be138dda6d --- /dev/null +++ b/cobigen-templates/sql-openapi-app/context.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/sql-openapi-app/templates.xml b/cobigen-templates/sql-openapi-app/templates.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java new file mode 100644 index 0000000000..4b0120a869 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java @@ -0,0 +1,25 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides operations to identify and process SQL specific information + * + */ +public class SQLUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public SQLUtil() { + + // Empty for CobiGen to automatically instantiate it + } + +} diff --git a/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/context.xml b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/context.xml new file mode 100644 index 0000000000..7dc46c7425 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/context.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates.xml b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates.xml new file mode 100644 index 0000000000..44e8feb936 --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/${variables.entityName}Entity.sql.ftl b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/${variables.entityName}Entity.sql.ftl new file mode 100644 index 0000000000..eb8f77623d --- /dev/null +++ b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/${variables.entityName}Entity.sql.ftl @@ -0,0 +1,23 @@ +CREATE TABLE ${variables.entityName?upper_case} ( + ID DECIMAL(10,0), + VERSION INTEGER NOT NULL, +<#list pojo.fields as field> +<#if !field.type?starts_with("List<") && !field.type?starts_with("Set<")> + <#if field.type?contains("Entity") || field.type=='long' || field.type=='java.lang.Long'> + <#assign type = 'DECIMAL(10,0)'> + <#elseif field.type=='int' || field.type=='java.lang.Integer' || field.type=='java.time.Year' || field.type=='java.time.Month'> + <#assign type = 'INTEGER'> + <#elseif field.type=='java.time.Instant' || field.type=='java.sql.Timestamp'> + <#assign type = 'TIMESTAMP'> + <#elseif field.type=='java.util.Date'> + <#assign type = 'DATE'> + <#elseif field.type=='boolean'> + <#assign type = 'NUMBER(1) DEFAULT 0'> + <#else> + <#assign type = 'VARCHAR2(255 CHAR)'> + + ${field.name?upper_case?right_pad(30)}${type}, + + + CONSTRAINT PK_${variables.entityName?upper_case} PRIMARY KEY(ID) +) \ No newline at end of file