forked from telosys-tools-beta/java8-commons-T312
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXxxPersistenceFake_java.vm
144 lines (125 loc) · 3.95 KB
/
XxxPersistenceFake_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#checkId($entity)
#parse("include/init_var_global.vm")
#parse("include/init_var_entity.vm")
#parse("include/java_header.vm")
package ${target.javaPackageFromFolder($SRC)};
import java.util.List;
#foreach( $import in $java.imports($entity.keyAttributes) )
import $import;
#end
import javax.inject.Named;
import ${recordPackage}.${recordClass};
import ${ROOT_PKG}.persistence.${persistenceServiceInterface};
import ${fakeCommonsPackage}.GenericFakeDAO;
/**
* ${entity.name} persistence service - FAKE implementation
*
* @author Telosys
*
*/
@Named("${persistenceServiceInterface}")
public class $persistenceServiceClass extends GenericFakeDAO<${recordClass}> implements $persistenceServiceInterface {
/**
* Constructor
*/
public $persistenceServiceClass() {
super(${recordClass}.class);
}
/**
* Creates a new bean instance and set its primary key value(s)
*
#foreach( $field in $keyFields )
* @param ${field.name}
#end
* @return the new instance
*/
private ${recordClass} newInstanceWithPrimaryKey($fn.argumentsListWithType($keyFields)) {
${recordClass} record = new ${recordClass}();
#foreach( $field in $keyFields )
record.${field.setter}(${field.name});
#end
return record;
}
//-------------------------------------------------------------------------------------
// Generic DAO abstract methods implementations
//-------------------------------------------------------------------------------------
@Override
protected String getKey(${recordClass} record) {
return buildKeyString($fn.argumentsListWithGetter("record", $keyFields));
}
@Override
protected void setAutoIncrementedKey(${recordClass} record, long value) {
#if( $entity.hasAutoIncrementedKey() )
#if( $entity.autoincrementedKeyAttribute.isIntegerType() )
record.${entity.autoincrementedKeyAttribute.setter}(toInt(value));
#elseif ( $entity.autoincrementedKeyAttribute.isShortType() )
record.${entity.autoincrementedKeyAttribute.setter}(toShort(value));
#else
//record.${entity.autoincrementedKeyAttribute.setter}((${entity.autoincrementedKeyAttribute.type})value);
record.${entity.autoincrementedKeyAttribute.setter}(value);
#end
#else
throw new IllegalStateException("Unexpected call to method 'setAutoIncrementedKey'");
#end
}
//-------------------------------------------------------------------------------------
// Persistence interface implementations
//-------------------------------------------------------------------------------------
@Override
public long countAll() {
return super.doCountAll();
}
@Override
public ${recordClass} create(${recordClass} record) {
#if( $entity.hasAutoIncrementedKey() )
super.doCreateAutoIncremented(record);
#else
super.doCreate(record);
#end
return record;
}
@Override
public boolean delete(${recordClass} record) {
return super.doDelete(record);
}
@Override
public boolean deleteById($fn.argumentsListWithWrapperType($keyFields)) {
${recordClass} record = newInstanceWithPrimaryKey($fn.argumentsList($keyFields));
return super.doDelete(record);
}
@Override
public boolean exists(${recordClass} record) {
return super.doExists(record);
}
@Override
public boolean exists($fn.argumentsListWithWrapperType($keyFields)) {
${recordClass} record = newInstanceWithPrimaryKey($fn.argumentsList($keyFields));
return super.doExists(record);
}
@Override
public List<${recordClass}> findAll() {
return super.doFindAll();
}
@Override
public ${recordClass} findById($fn.argumentsListWithWrapperType($keyFields)) {
${recordClass} record = newInstanceWithPrimaryKey($fn.argumentsList($keyFields));
return super.doFind(record);
}
@Override
public ${recordClass} save(${recordClass} record) {
if (super.doExists(record)) {
super.doUpdate(record);
} else {
#if( $entity.hasAutoIncrementedKey() )
super.doCreateAutoIncremented(record);
#else
super.doCreate(record);
#end
}
return record;
}
@Override
public boolean update(${recordClass} record) {
return super.doUpdate(record);
}
}