update model for commands
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## --------------------------------------------------
|
||||
#if ( !($entity.hasTag("BaseModel")) )
|
||||
#cancel("Not a Base Model")
|
||||
#end
|
||||
## --------------------------------------------------
|
||||
/*
|
||||
* Java backend model class for entity "${entity.name}"
|
||||
* Created on $now.date ( $now.time )
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
## --------------------------------------------------
|
||||
#if ( !($entity.hasTag("Command")) )
|
||||
#cancel("Not a Command")
|
||||
#end
|
||||
## --------------------------------------------------
|
||||
/*
|
||||
* Java command model class for entity "${entity.name}"
|
||||
* Created on $now.date ( $now.time )
|
||||
* Generated by $generator.name ( version $generator.version )
|
||||
*/
|
||||
package ${target.javaPackageFromFolder("backend/${SRC}")};
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
#foreach( $import in $java.imports($entity) )
|
||||
import $import;
|
||||
#end
|
||||
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
## Data fields = fields not in Primary Key and not in selected Links
|
||||
#set( $dataFields = $entity.getAttributesByCriteria( $const.NOT_KEY, $const.NOT_IN_SELECTED_LINKS ) )
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
## Link fields = fields not in Primary Key and used as FK in selected Links
|
||||
#set( $linkFields = $entity.getAttributesByCriteria( $const.NOT_KEY, $const.IN_SELECTED_LINKS ) )
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* Command model class for entity "${entity.name}"
|
||||
*
|
||||
* @author Telosys Tools Generator
|
||||
*
|
||||
*/
|
||||
public#if( $entity.isAbstract() ) abstract#end class ${entity.name}#if( $entity.hasSuperClass() ) extends $entity.superClass#end implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY PRIMARY KEY
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $field in $entity.keyAttributes )
|
||||
private $field.formattedType(10) $field.formattedName(12) #if($field.hasInitialValue())= ${field.initialValue} #end;
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY DATA FIELDS
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $field in $dataFields )
|
||||
private $field.formattedType(10) $field.formattedName(12) #if($field.hasInitialValue())= ${field.initialValue} #end;
|
||||
#end
|
||||
#foreach( $field in $linkFields )
|
||||
// Attribute "$field.name" is a link
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY LINKS ( RELATIONSHIP )
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $link in $entity.selectedLinks )
|
||||
private ${link.formattedFieldType(10)} $link.formattedFieldName(12) ;
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// CONSTRUCTOR(S)
|
||||
//----------------------------------------------------------------------
|
||||
public ${entity.name}() {
|
||||
super();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTER & SETTER FOR "KEY FIELD(S)"
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $attribute in $entity.keyAttributes )
|
||||
public void ${attribute.setter}( $attribute.type $attribute.name ) {
|
||||
this.$attribute.name = $attribute.name ;
|
||||
}
|
||||
public $attribute.type ${attribute.getter}() {
|
||||
return this.$attribute.name;
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTERS & SETTERS FOR "DATA FIELDS"
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $attribute in $dataFields )
|
||||
public void ${attribute.setter}( $attribute.type $attribute.name ) {
|
||||
this.$attribute.name = $attribute.name ;
|
||||
}
|
||||
public $attribute.type ${attribute.getter}() {
|
||||
return this.$attribute.name;
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTERS & SETTERS FOR LINKS
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $link in $entity.selectedLinks )
|
||||
public void ${link.setter}( ${link.formattedFieldType(0)} ${link.formattedFieldName(0)} ) {
|
||||
this.${link.formattedFieldName(0)} = ${link.formattedFieldName(0)};
|
||||
}
|
||||
public ${link.formattedFieldType(0)} ${link.getter}() {
|
||||
return this.${link.formattedFieldName(0)};
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
#if( $entity.isAbstract() )
|
||||
static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
|
||||
= new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
.setVisibility(com.fasterxml.jackson.annotation.PropertyAccessor.FIELD, com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY)
|
||||
.configure(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
|
||||
public abstract CommandWrapper serialize() throws java.io.IOException;
|
||||
#else
|
||||
#if ( $entity.name != "CommandWrapper" )
|
||||
public CommandWrapper serialize() throws java.io.IOException {
|
||||
CommandWrapper wrapper = new CommandWrapper();
|
||||
wrapper.setType(${entity.name}.class.getSimpleName());
|
||||
wrapper.setPayload(OBJECT_MAPPER.writeValueAsBytes(this));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static $entity.name deserialize(CommandWrapper wrapper) throws java.io.IOException {
|
||||
return OBJECT_MAPPER.readValue(wrapper.getPayload(), ${entity.name}.class);
|
||||
}
|
||||
|
||||
public static boolean isType(CommandWrapper wrapper) {
|
||||
return wrapper.getType().equals(${entity.name}.class.getSimpleName());
|
||||
}
|
||||
#else
|
||||
public $entity.name copyIds(CommandWrapper wrapper) {
|
||||
setTransaction(wrapper.getTransaction());
|
||||
setRequest(wrapper.getRequest());
|
||||
return this;
|
||||
}
|
||||
|
||||
public $entity.name generateIds() {
|
||||
setTransaction(java.util.UUID.randomUUID().toString());
|
||||
setRequest(java.util.UUID.randomUUID().toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ${entity.name}(CommandWrapper wrapper) {
|
||||
this();
|
||||
copyIds(wrapper);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// toString METHOD
|
||||
//----------------------------------------------------------------------
|
||||
## This function generates a 'toString' method with 4 blanks before each line
|
||||
## $java.toStringMethod($fn.concatLists($entity.keyAttributes, $dataFields), 4)
|
||||
$java.toStringMethod($entity, 1)
|
||||
}
|
||||
@@ -16,6 +16,19 @@
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.20</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
## --------------------------------------------------
|
||||
#if ( !($entity.hasTag("BaseModel")) )
|
||||
#cancel("Not a Base Model")
|
||||
#end
|
||||
## --------------------------------------------------
|
||||
#set( $env.language = 'TypeScript' )
|
||||
#foreach( $link in $entity.links )
|
||||
import $link.fieldType from "./${link.fieldType}";
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#foreach( $entity in $model.allEntities )
|
||||
#if ( $entity.hasTag("BaseModel") )
|
||||
import $entity.name from "./${entity.name}";
|
||||
#end
|
||||
#end
|
||||
|
||||
export type {
|
||||
#foreach( $entity in $model.allEntities )
|
||||
#if ( $entity.hasTag("BaseModel") )
|
||||
$entity.name,
|
||||
#end
|
||||
#end
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
## --------------------------------------------------
|
||||
#if ( !($entity.hasTag("Command")) )
|
||||
#cancel("Not a Command")
|
||||
#end
|
||||
## --------------------------------------------------
|
||||
/*
|
||||
* Java command model class for entity "${entity.name}"
|
||||
* Created on $now.date ( $now.time )
|
||||
* Generated by $generator.name ( version $generator.version )
|
||||
*/
|
||||
package ${target.javaPackageFromFolder("persistence/${SRC}")};
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
#foreach( $import in $java.imports($entity) )
|
||||
import $import;
|
||||
#end
|
||||
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
## Data fields = fields not in Primary Key and not in selected Links
|
||||
#set( $dataFields = $entity.getAttributesByCriteria( $const.NOT_KEY, $const.NOT_IN_SELECTED_LINKS ) )
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
## Link fields = fields not in Primary Key and used as FK in selected Links
|
||||
#set( $linkFields = $entity.getAttributesByCriteria( $const.NOT_KEY, $const.IN_SELECTED_LINKS ) )
|
||||
##--------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* Command model class for entity "${entity.name}"
|
||||
*
|
||||
* @author Telosys Tools Generator
|
||||
*
|
||||
*/
|
||||
public#if( $entity.isAbstract() ) abstract#end class ${entity.name}#if( $entity.hasSuperClass() ) extends $entity.superClass#end implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY PRIMARY KEY
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $field in $entity.keyAttributes )
|
||||
private $field.formattedType(10) $field.formattedName(12) #if($field.hasInitialValue())= ${field.initialValue} #end;
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY DATA FIELDS
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $field in $dataFields )
|
||||
private $field.formattedType(10) $field.formattedName(12) #if($field.hasInitialValue())= ${field.initialValue} #end;
|
||||
#end
|
||||
#foreach( $field in $linkFields )
|
||||
// Attribute "$field.name" is a link
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// ENTITY LINKS ( RELATIONSHIP )
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $link in $entity.selectedLinks )
|
||||
private ${link.formattedFieldType(10)} $link.formattedFieldName(12) ;
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// CONSTRUCTOR(S)
|
||||
//----------------------------------------------------------------------
|
||||
public ${entity.name}() {
|
||||
super();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTER & SETTER FOR "KEY FIELD(S)"
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $attribute in $entity.keyAttributes )
|
||||
public void ${attribute.setter}( $attribute.type $attribute.name ) {
|
||||
this.$attribute.name = $attribute.name ;
|
||||
}
|
||||
public $attribute.type ${attribute.getter}() {
|
||||
return this.$attribute.name;
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTERS & SETTERS FOR "DATA FIELDS"
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $attribute in $dataFields )
|
||||
public void ${attribute.setter}( $attribute.type $attribute.name ) {
|
||||
this.$attribute.name = $attribute.name ;
|
||||
}
|
||||
public $attribute.type ${attribute.getter}() {
|
||||
return this.$attribute.name;
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// GETTERS & SETTERS FOR LINKS
|
||||
//----------------------------------------------------------------------
|
||||
#foreach( $link in $entity.selectedLinks )
|
||||
public void ${link.setter}( ${link.formattedFieldType(0)} ${link.formattedFieldName(0)} ) {
|
||||
this.${link.formattedFieldName(0)} = ${link.formattedFieldName(0)};
|
||||
}
|
||||
public ${link.formattedFieldType(0)} ${link.getter}() {
|
||||
return this.${link.formattedFieldName(0)};
|
||||
}
|
||||
|
||||
#end
|
||||
|
||||
#if( $entity.isAbstract() )
|
||||
static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
|
||||
= new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
.setVisibility(com.fasterxml.jackson.annotation.PropertyAccessor.FIELD, com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY)
|
||||
.configure(com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
|
||||
public abstract CommandWrapper serialize() throws java.io.IOException;
|
||||
#else
|
||||
#if ( $entity.name != "CommandWrapper" )
|
||||
public CommandWrapper serialize() throws java.io.IOException {
|
||||
CommandWrapper wrapper = new CommandWrapper();
|
||||
wrapper.setType(${entity.name}.class.getSimpleName());
|
||||
wrapper.setPayload(OBJECT_MAPPER.writeValueAsBytes(this));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public static $entity.name deserialize(CommandWrapper wrapper) throws java.io.IOException {
|
||||
return OBJECT_MAPPER.readValue(wrapper.getPayload(), ${entity.name}.class);
|
||||
}
|
||||
|
||||
public static boolean isType(CommandWrapper wrapper) {
|
||||
return wrapper.getType().equals(${entity.name}.class.getSimpleName());
|
||||
}
|
||||
#else
|
||||
public $entity.name copyIds(CommandWrapper wrapper) {
|
||||
setTransaction(wrapper.getTransaction());
|
||||
setRequest(wrapper.getRequest());
|
||||
return this;
|
||||
}
|
||||
|
||||
public $entity.name generateIds() {
|
||||
setTransaction(java.util.UUID.randomUUID().toString());
|
||||
setRequest(java.util.UUID.randomUUID().toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ${entity.name}(CommandWrapper wrapper) {
|
||||
this();
|
||||
copyIds(wrapper);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// toString METHOD
|
||||
//----------------------------------------------------------------------
|
||||
## This function generates a 'toString' method with 4 blanks before each line
|
||||
## $java.toStringMethod($fn.concatLists($entity.keyAttributes, $dataFields), 4)
|
||||
$java.toStringMethod($entity, 1)
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
## --------------------------------------------------
|
||||
#if ( !($entity.hasTag("BaseModel")) )
|
||||
#cancel("Not a Base Model")
|
||||
#end
|
||||
## --------------------------------------------------
|
||||
#if ( $entity.isJoinEntity() )
|
||||
#cancel("No JPA class for join entity")
|
||||
#end
|
||||
@@ -81,6 +85,9 @@ $jpa.linkAnnotations(4, $link, $entity.attributes)
|
||||
##--- Just @JoinColumn(s) annotation(s)
|
||||
## $jpa.linkJoinAnnotation(4, $link)
|
||||
## $jpa.linkJoinAnnotation(4, $link, $entity.attributes)
|
||||
#if( !($link.optional) )
|
||||
@Column(nullable = false)
|
||||
#end
|
||||
private ${link.formattedFieldType(10)} $link.fieldName ;
|
||||
|
||||
#end
|
||||
|
||||
@@ -22,6 +22,16 @@
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.20</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
-- Generated by Telosys ( https://www.telosys.org/ )
|
||||
-- $now.date ($now.time)
|
||||
#set( $env.database = 'PostgreSQL' )
|
||||
## ---------------------------------------
|
||||
## For each entity : CREATE TABLE
|
||||
## ---------------------------------------
|
||||
#foreach( $entity in $model.allEntites )
|
||||
## CREATE TABLE IF NOT EXISTS $entity.sqlTableName
|
||||
## use $entity.databaseSchema if necessary
|
||||
CREATE TABLE $entity.sqlTableName
|
||||
(
|
||||
## COLUMNS DEFINITION :
|
||||
#foreach( $attribute in $entity.attributes )
|
||||
#if( $foreach.hasNext() || $entity.hasPrimaryKey() )
|
||||
#set($EOL=",")
|
||||
#else
|
||||
#set($EOL="")
|
||||
#end
|
||||
## $sql.columnName($attribute) $sql.columnType($attribute) $sql.columnConstraints($attribute)$EOL
|
||||
$attribute.sqlColumnName $attribute.sqlColumnType ${attribute.sqlColumnConstraints}$EOL
|
||||
#end
|
||||
## PRIMARY KEY DEFINITION :
|
||||
#if( $entity.hasPrimaryKey() )
|
||||
## PRIMARY KEY ($sql.pkColumns($entity))
|
||||
PRIMARY KEY ($entity.sqlPrimaryKeyColumnsAsString)
|
||||
#end
|
||||
);
|
||||
|
||||
#end## foreach( $entity )
|
||||
|
||||
## ---------------------------------------------------------
|
||||
## For each Foreign Key in each entity : CREATE FOREIGN KEY
|
||||
## ---------------------------------------------------------
|
||||
#foreach( $entity in $model.allEntites )
|
||||
#if ( $entity.hasForeignKeys() )
|
||||
#set($tableName = $entity.sqlTableName )
|
||||
#foreach( $fk in $entity.databaseForeignKeys )
|
||||
ALTER TABLE $tableName
|
||||
ADD CONSTRAINT "$fk.name" FOREIGN KEY($fk.sqlOriginColumnsAsString)
|
||||
REFERENCES ${fk.sqlReferencedTableName}($fk.sqlReferencedColumnsAsString) ;
|
||||
CREATE INDEX ON $tableName($fk.sqlOriginColumnsAsString) ;
|
||||
#end## foreach( $fk )
|
||||
|
||||
#end## if has FK
|
||||
#end## foreach( $entity )
|
||||
@@ -11,8 +11,8 @@
|
||||
### PlantUML ###
|
||||
Model diagram ; model.plantuml ; plantuml ; plantuml/class-diag_txt.vm ; 1
|
||||
|
||||
### PostgreSQL Datenbank ###
|
||||
PostgreSQL create tables ; postgresql-create-tables.sql ; sql ; sql/postgresql-create-tables_sql.vm ; 1
|
||||
### PostgreSQL Datenbank ### (durch Hibernate generiert)
|
||||
#PostgreSQL create tables ; postgresql-create-tables.sql ; sql ; sql/postgresql-create-tables_sql.vm ; 1
|
||||
|
||||
### Frontend ###
|
||||
.npmrc ; .npmrc ; frontend ; frontend/.npmrc.vm ; 1
|
||||
@@ -24,8 +24,10 @@ TypeScript Models ; ${BEANNAME}.ts ; frontend
|
||||
|
||||
### Backend ###
|
||||
Java Backend Models ; ${BEANNAME}.java ; backend/${SRC}/${ROOT_PKG}/backend ; backend/backend_entity_java.vm
|
||||
Java Command Models (B) ; ${BEANNAME}.java ; backend/${SRC}/${ROOT_PKG}/backend ; backend/command_entity_java.vm
|
||||
Maven Backend pom.xml ; pom.xml ; backend ; backend/pom_xml.vm ; 1
|
||||
|
||||
### Persistence ###
|
||||
Java Persistence Models ; ${BEANNAME}.java ; persistence/${SRC}/${ROOT_PKG}/persistence ; persistence/persistence_entity_java.vm
|
||||
Java Command Models (P) ; ${BEANNAME}.java ; persistence/${SRC}/${ROOT_PKG}/persistence ; persistence/command_entity_java.vm
|
||||
Maven Persistence pom.xml ; pom.xml ; persistence ; persistence/pom_xml.vm ; 1
|
||||
|
||||
Reference in New Issue
Block a user