Skip to content

Commit

Permalink
devonfw#860 template structure and sql util class
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumfate committed Aug 12, 2022
1 parent 46bb194 commit cb9e16d
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cobigen-eclipse/cobigen-eclipse-test/.classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/">
Expand Down Expand Up @@ -32,5 +30,7 @@
<classpathentry exported="true" kind="lib" path="lib/system-lambda.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xmlunit.jar"/>
<classpathentry exported="true" kind="lib" path="lib/zt-exec.jar"/>
<classpathentry exported="true" kind="lib" path="lib/awaitility.jar" sourcepath="C:/Users/mbrunnli/.m2/repository/org/awaitility/awaitility/4.1.1/awaitility-4.1.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest.jar"/>
<classpathentry kind="output" path="eclipse-target/classes"/>
</classpath>
13 changes: 13 additions & 0 deletions cobigen-templates/sql-openapi-app/context.xml
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.
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
}

}
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>
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>
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)
)

0 comments on commit cb9e16d

Please sign in to comment.