7
7
import java .util .Map .Entry ;
8
8
import java .util .concurrent .ExecutorService ;
9
9
10
- import info .unterrainer .commons .httpserver .daos .BasicDao ;
10
+ import info .unterrainer .commons .httpserver .daos .CoreDao ;
11
11
import info .unterrainer .commons .httpserver .daos .DaoTransaction ;
12
- import info .unterrainer .commons .httpserver .daos .DaoTransactionManager ;
13
12
import info .unterrainer .commons .httpserver .enums .Attribute ;
14
13
import info .unterrainer .commons .httpserver .enums .Endpoint ;
15
14
import info .unterrainer .commons .httpserver .enums .QueryField ;
33
32
@ RequiredArgsConstructor (access = AccessLevel .PACKAGE )
34
33
public class GenericHandlerGroup <P extends BasicJpa , J extends BasicJson , E > implements HandlerGroup {
35
34
36
- private final BasicDao <P , E > dao ;
35
+ private final CoreDao <P , E > dao ;
37
36
private final Class <P > jpaType ;
38
37
private final Class <J > jsonType ;
39
- private final DaoTransactionManager <E > daoTransactionManager ;
40
38
private final JsonMapper jsonMapper ;
41
39
private final MapperFacade orikaMapper ;
42
40
private final String path ;
@@ -47,7 +45,7 @@ public class GenericHandlerGroup<P extends BasicJpa, J extends BasicJson, E> imp
47
45
private final ExecutorService executorService ;
48
46
private final HandlerUtils hu = new HandlerUtils ();
49
47
private final String tenantIdRowName ;
50
- private final BasicDao <? extends BasicJpa , E > tenantDao ;
48
+ private final CoreDao <? extends BasicJpa , E > tenantDao ;
51
49
private final Class <? extends BasicJpa > tenantJpaType ;
52
50
private final String fieldRowName ;
53
51
private final String tenantRowName ;
@@ -97,7 +95,7 @@ private Role[] rolesFor(final List<Endpoint> endpointList) {
97
95
}
98
96
99
97
private void getEntry (final Context ctx ) {
100
- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
98
+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
101
99
102
100
P jpa = hu .getJpaById (ctx , transaction .getManager (), dao );
103
101
J json = orikaMapper .map (jpa , jsonType );
@@ -130,7 +128,7 @@ private void getList(final Context ctx) {
130
128
e .getMessage ());
131
129
}
132
130
133
- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
131
+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
134
132
135
133
ListJson <P > bList = dao .getList (transaction .getManager (), offset , size , interceptorResult .getSelectClause (),
136
134
interceptorResult .getJoinClause (), interceptorResult .getWhereClause (), interceptorResult .getParams (),
@@ -152,7 +150,7 @@ private void create(final Context ctx) throws IOException {
152
150
try {
153
151
J json = jsonMapper .fromStringTo (jsonType , b );
154
152
P mappedJpa = orikaMapper .map (json , jpaType );
155
- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
153
+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
156
154
157
155
mappedJpa = extensions .runPreInsert (ctx , transaction .getManager (), json , mappedJpa , executorService );
158
156
P createdJpa = dao .create (transaction .getManager (), mappedJpa );
@@ -170,38 +168,39 @@ private void create(final Context ctx) throws IOException {
170
168
}
171
169
172
170
private void fullUpdate (final Context ctx ) throws IOException {
173
- P jpa = hu .getJpaById (ctx , dao );
171
+ DaoTransaction <E > transaction = dao .getTransactionManager ().beginTransaction ();
172
+ P jpa = hu .getJpaById (ctx , transaction .getManager (), dao );
174
173
try {
175
174
J json = jsonMapper .fromStringTo (jsonType , ctx .body ());
176
175
P mappedJpa = orikaMapper .map (json , jpaType );
177
176
mappedJpa .setId (jpa .getId ());
178
177
mappedJpa .setCreatedOn (jpa .getCreatedOn ());
179
178
mappedJpa .setEditedOn (jpa .getEditedOn ());
180
- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
181
179
182
180
mappedJpa = extensions .runPreModify (ctx , transaction .getManager (), jpa .getId (), json , jpa , mappedJpa ,
183
181
executorService );
184
- P persistedJpa = dao .update (mappedJpa );
182
+ P persistedJpa = dao .update (transaction . getManager (), mappedJpa );
185
183
186
184
J r = orikaMapper .map (persistedJpa , jsonType );
187
185
r = extensions .runPostModify (ctx , transaction .getManager (), jpa .getId (), json , jpa , mappedJpa , persistedJpa ,
188
186
r , executorService );
189
187
190
- transaction .end ();
191
188
ctx .attribute (Attribute .RESPONSE_OBJECT , r );
192
189
193
190
} catch (JsonProcessingException | JsonMappingException e ) {
194
191
throw new BadRequestException ();
192
+ } finally {
193
+ transaction .end ();
195
194
}
196
195
}
197
196
198
197
private void delete (final Context ctx ) {
199
198
ctx .attribute (Attribute .RESPONSE_OBJECT , null );
200
199
Long id = hu .checkAndGetId (ctx );
201
- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
200
+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
202
201
203
202
id = extensions .runPreDelete (ctx , transaction .getManager (), id , executorService );
204
- dao .delete (id );
203
+ dao .delete (transaction . getManager (), id );
205
204
ctx .status (204 );
206
205
extensions .runPostDelete (ctx , transaction .getManager (), id , executorService );
207
206
0 commit comments