Files
model/TelosysTools/templates/infinimotion/persistence/persistence_entity_java.vm
2025-11-01 01:23:58 +01:00

156 lines
5.3 KiB
Plaintext

## --------------------------------------------------
#if ( !($entity.hasTag("BaseModel")) )
#cancel("Not a Base Model")
#end
## --------------------------------------------------
#if ( $entity.isJoinEntity() )
#cancel("No JPA class for join entity")
#end
## --------------------------------------------------
#checkId($entity)
## #set($recordClass = "${entity.name}Record" )
## #set($recordInstance = $fn.uncapitalize($entity.name) )
##
#set($jpaEntityClass = "${entity.name}" )
#set($jpaEntityIdClass = "${entity.name}Id" )
##
## #set($jpaMapperClass = "${entity.name}RecordMapper" )
## #set($jpaMapperInstance = "${recordInstance}Mapper" )
##
/*
* Created on $now.date ( $now.time )
* Generated by Telosys ( http://www.telosys.org/ ) version $generator.version
*/
##---------------------------------------------------------------------------------------
## JPA CONFIGURATION
##---------------------------------------------------------------------------------------
## Define the default collection type to be used (default is "java.util.List" )
## #set($env.collectionType = "java.util.Set")
## #set($env.collectionType = "java.util.Collection")
## ---------------------------
## Define if "targetEntity" must be generated in @ManyToMany or @OneToMany
## #set($jpa.genTargetEntity = true)
## ---------------------------
## Define default value (true or false) for "insertable" and "updatable" in "@JoinColumn"
## #set($jpa.joinColumnInsertable = true)
## #set($jpa.joinColumnUpdatable = true)
## ---------------------------
## Set default FETCH-TYPE for each cardinality ( "LAZY" or "EAGER" )
## #set($jpa.manyToOneFetchType = "LAZY" )
## #set($jpa.oneToOneFetchType = "LAZY" )
## #set($jpa.oneToManyFetchType = "EAGER" )
## #set($jpa.manyToManyFetchType = "EAGER" )
##---------------------------------------------------------------------------------------
package ${target.javaPackageFromFolder("persistence/${SRC}")};
## IF ENTITY HAS A COMPOSITE PRIMARY KEY => GENERATE AN 'ID CLASS' FOR THIS PRIMARY KEY
#if ( $entity.hasCompositePrimaryKey() )
$generator.generate($target.entityName , "${jpaEntityIdClass}.java", $target.folder, "persistence/persistence_entity_id_java.vm" )
#end
import java.io.Serializable;
#foreach( $import in $java.imports($entity) )
import $import;
#end
import jakarta.persistence.*;
## #foreach( $import in $jpa.imports($entity) )
## import $import;
## #end
/**
* JPA entity class for "${entity.name}"
*
* @author Telosys
*
*/
$jpa.entityAnnotations(0, $entity)
## IF ENTITY HAS A COMPOSITE PRIMARY KEY => DECLARE 'ID CLASS' FOR THIS PRIMARY KEY
#if ( $entity.hasCompositePrimaryKey() )
@IdClass(${jpaEntityIdClass}.class)
#end
@lombok.EqualsAndHashCode
public class ${entity.name} implements Serializable {
private static final long serialVersionUID = 1L;
//--- ENTITY PRIMARY KEY
#foreach( $attribute in $entity.keyAttributes )
$jpa.fieldAnnotations(4, $attribute)
private $attribute.formattedType(10) $attribute.name #if($attribute.hasInitialValue())= ${attribute.ini} #end;
#end
//--- ENTITY DATA FIELDS
#foreach( $attribute in $entity.nonKeyAttributes )
$jpa.fieldAnnotations(4, $attribute)
private $attribute.formattedType(10) $attribute.name #if($attribute.hasInitialValue())= ${attribute.ini} #end;
#end
//--- ENTITY LINKS ( RELATIONSHIP )
#foreach( $link in $entity.links )
## all annotations : Cardinality, JoinColumn(s), etc
##--- with "insertable=false, updatable=false" if attribute already mapped
$jpa.linkAnnotations(4, $link, $entity.attributes)
##--- no "insertable=false, updatable=false" if already mapped
## $jpa.linkAnnotations(4, $link)
##--- Just @Cardinality annotation
## $jpa.linkCardinalityAnnotation(4, $link)
##--- Just @JoinColumn(s) annotation(s)
## $jpa.linkJoinAnnotation(4, $link)
## $jpa.linkJoinAnnotation(4, $link, $entity.attributes)
## Workaround, sonst undefined...
#if( "${link.optional}" == "true" )
@JoinColumn(nullable = true)
#else
@JoinColumn(nullable = false)
#end
private ${link.formattedFieldType(10)} $link.fieldName ;
#end
/**
* Constructor
*/
public ${entity.name}() {
super();
}
//--- GETTERS & SETTERS FOR FIELDS
#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
#foreach( $attribute in $entity.nonKeyAttributes )
public void ${attribute.setter}( $attribute.type $attribute.name ) {
this.$attribute.name = $attribute.name ;
}
public $attribute.type ${attribute.getter}() {
return this.$attribute.name;
}
#end
//--- GETTERS FOR LINKS
#foreach( $link in $entity.selectedLinks )
public ${link.formattedFieldType(0)} ${link.getter}() {
return this.${link.formattedFieldName(0)};
}
#end
//--- SETTERS FOR LINKS
#foreach( $link in $entity.selectedLinks )
public void ${link.setter}( ${link.formattedFieldType(0)} $link.fieldName ) {
this.$link.fieldName = $link.fieldName ;
}
#end
//--- toString specific method
@Override
## This function generates a 'toString' method with indentation level = 1 (1 tab)
## $java.toStringMethod($fn.concatLists($entity.keyAttributes, $entity.nonKeyAttributes), 4)## no EOL
$java.toStringMethod($entity, 1)
}