forked from devonfw/cobigen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw#860 template structure and sql util class
- Loading branch information
1 parent
46bb194
commit cb9e16d
Showing
7 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<contextConfiguration xmlns="http://capgemini.com/devonfw/cobigen/ContextConfiguration" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
version="3.0"> | ||
<trigger id="sql_openapi_app" type="openapi"> | ||
|
||
</trigger> | ||
<tags> | ||
<tag name="OpenAPI"></tag> | ||
<tag name="SQL"></tag> | ||
<tag name="App"></tag> | ||
</tags> | ||
</contextConfiguration> |
Empty file.
25 changes: 25 additions & 0 deletions
25
.../templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/SQLUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<contextConfiguration xmlns="http://capgemini.com/devonfw/cobigen/ContextConfiguration" version="2.1"> | ||
|
||
<trigger id="sql_java_app" type="java" templateFolder="sql_java_app"> | ||
<containerMatcher type="package" value="((.+\.)?([^\.]+))\.([^\.]+)\.dataaccess\.api" retrieveObjectsRecursively="false" /> | ||
<matcher type="fqn" value="((.+\.)?([^\.]+))\.([^\.]+)\.dataaccess\.api\.([^\.]+)Entity"> | ||
<variableAssignment type="regex" key="rootPackage" value="1" /> | ||
<variableAssignment type="regex" key="domain" value="3" /> | ||
<variableAssignment type="regex" key="component" value="4" /> | ||
<variableAssignment type="regex" key="entityName" value="5" /> | ||
</matcher> | ||
</trigger> | ||
</contextConfiguration> |
21 changes: 21 additions & 0 deletions
21
cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<templatesConfiguration xmlns="http://capgemini.com/devonfw/cobigen/TemplatesConfiguration" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="4.0"> | ||
|
||
<templates> | ||
<templateExtension ref="${variables.entityName}Entity.sql" mergeStrategy="textmerge_override"/> | ||
</templates> | ||
<!-- ${variables.entityName}Entity.java --> | ||
|
||
<templateScans> | ||
<templateScan name="ts_scan" templatePath="templates" destinationPath="src/main" /> | ||
</templateScans> | ||
|
||
<increments> | ||
<increment name="sql_java_app" description="SQL Script creation by Entity" ><!-- explanation="Generates a SQL create table script based on provided java entity class." --> | ||
<templateRef ref="${variables.entityName}Entity.sql" /> | ||
<!-- ${variables.entityName}Entity.sql--> | ||
</increment> | ||
</increments> | ||
|
||
</templatesConfiguration> |
23 changes: 23 additions & 0 deletions
23
...s-devon4j/src/main/templates/sql_java_app/templates/${variables.entityName}Entity.sql.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)'> | ||
</#if> | ||
${field.name?upper_case?right_pad(30)}${type}, | ||
</#if> | ||
</#list> | ||
CONSTRAINT PK_${variables.entityName?upper_case} PRIMARY KEY(ID) | ||
) |