-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdomain_entity_java.vm
117 lines (103 loc) · 4 KB
/
domain_entity_java.vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
## --------------------------------------------------
#if ( $entity.isJoinEntity() )
#cancel("No JPA class for join entity")
#end
## --------------------------------------------------
#checkId($entity)
##---------------------------------------------------------------------------------------
## 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, @OneToMany, etc
## #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(${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, "domainJpaEntityId_java.vm" )
#end
import java.io.Serializable;
#foreach( $import in $java.imports($entity) )
import $import;
#end
#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
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.initialValue} #end;
#end
//--- ENTITY DATA FIELDS
#foreach( $attribute in $entity.nonKeyAttributes )
$jpa.fieldAnnotations(4, $attribute)
private $attribute.formattedType(10) $attribute.name #if($attribute.hasInitialValue())= ${attribute.initialValue} #end;
#end
//--- ENTITY LINKS ( RELATIONSHIP )
#foreach( $link in $entity.links )
## all annotations : Cardinality, JoinColumn(s), etc
$jpa.linkAnnotations(4, $link, $entity.attributes)
## $jpa.linkCardinalityAnnotation(4, $link)
## $jpa.linkJoinAnnotation(4, $link)
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
//--- toString specific method
@Override
## This function generates a 'toString' method with 4 blanks before each line
$java.toStringMethod($fn.concatLists($entity.keyAttributes, $entity.nonKeyAttributes), 4)## no EOL
}