77import java .util .Map .Entry ;
88import java .util .concurrent .ExecutorService ;
99
10- import info .unterrainer .commons .httpserver .daos .BasicDao ;
10+ import info .unterrainer .commons .httpserver .daos .CoreDao ;
1111import info .unterrainer .commons .httpserver .daos .DaoTransaction ;
12- import info .unterrainer .commons .httpserver .daos .DaoTransactionManager ;
1312import info .unterrainer .commons .httpserver .enums .Attribute ;
1413import info .unterrainer .commons .httpserver .enums .Endpoint ;
1514import info .unterrainer .commons .httpserver .enums .QueryField ;
3332@ RequiredArgsConstructor (access = AccessLevel .PACKAGE )
3433public class GenericHandlerGroup <P extends BasicJpa , J extends BasicJson , E > implements HandlerGroup {
3534
36- private final BasicDao <P , E > dao ;
35+ private final CoreDao <P , E > dao ;
3736 private final Class <P > jpaType ;
3837 private final Class <J > jsonType ;
39- private final DaoTransactionManager <E > daoTransactionManager ;
4038 private final JsonMapper jsonMapper ;
4139 private final MapperFacade orikaMapper ;
4240 private final String path ;
@@ -47,7 +45,7 @@ public class GenericHandlerGroup<P extends BasicJpa, J extends BasicJson, E> imp
4745 private final ExecutorService executorService ;
4846 private final HandlerUtils hu = new HandlerUtils ();
4947 private final String tenantIdRowName ;
50- private final BasicDao <? extends BasicJpa , E > tenantDao ;
48+ private final CoreDao <? extends BasicJpa , E > tenantDao ;
5149 private final Class <? extends BasicJpa > tenantJpaType ;
5250 private final String fieldRowName ;
5351 private final String tenantRowName ;
@@ -97,7 +95,7 @@ private Role[] rolesFor(final List<Endpoint> endpointList) {
9795 }
9896
9997 private void getEntry (final Context ctx ) {
100- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
98+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
10199
102100 P jpa = hu .getJpaById (ctx , transaction .getManager (), dao );
103101 J json = orikaMapper .map (jpa , jsonType );
@@ -130,7 +128,7 @@ private void getList(final Context ctx) {
130128 e .getMessage ());
131129 }
132130
133- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
131+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
134132
135133 ListJson <P > bList = dao .getList (transaction .getManager (), offset , size , interceptorResult .getSelectClause (),
136134 interceptorResult .getJoinClause (), interceptorResult .getWhereClause (), interceptorResult .getParams (),
@@ -152,7 +150,7 @@ private void create(final Context ctx) throws IOException {
152150 try {
153151 J json = jsonMapper .fromStringTo (jsonType , b );
154152 P mappedJpa = orikaMapper .map (json , jpaType );
155- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
153+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
156154
157155 mappedJpa = extensions .runPreInsert (ctx , transaction .getManager (), json , mappedJpa , executorService );
158156 P createdJpa = dao .create (transaction .getManager (), mappedJpa );
@@ -170,38 +168,39 @@ private void create(final Context ctx) throws IOException {
170168 }
171169
172170 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 );
174173 try {
175174 J json = jsonMapper .fromStringTo (jsonType , ctx .body ());
176175 P mappedJpa = orikaMapper .map (json , jpaType );
177176 mappedJpa .setId (jpa .getId ());
178177 mappedJpa .setCreatedOn (jpa .getCreatedOn ());
179178 mappedJpa .setEditedOn (jpa .getEditedOn ());
180- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
181179
182180 mappedJpa = extensions .runPreModify (ctx , transaction .getManager (), jpa .getId (), json , jpa , mappedJpa ,
183181 executorService );
184- P persistedJpa = dao .update (mappedJpa );
182+ P persistedJpa = dao .update (transaction . getManager (), mappedJpa );
185183
186184 J r = orikaMapper .map (persistedJpa , jsonType );
187185 r = extensions .runPostModify (ctx , transaction .getManager (), jpa .getId (), json , jpa , mappedJpa , persistedJpa ,
188186 r , executorService );
189187
190- transaction .end ();
191188 ctx .attribute (Attribute .RESPONSE_OBJECT , r );
192189
193190 } catch (JsonProcessingException | JsonMappingException e ) {
194191 throw new BadRequestException ();
192+ } finally {
193+ transaction .end ();
195194 }
196195 }
197196
198197 private void delete (final Context ctx ) {
199198 ctx .attribute (Attribute .RESPONSE_OBJECT , null );
200199 Long id = hu .checkAndGetId (ctx );
201- DaoTransaction <E > transaction = daoTransactionManager .beginTransaction ();
200+ DaoTransaction <E > transaction = dao . getTransactionManager () .beginTransaction ();
202201
203202 id = extensions .runPreDelete (ctx , transaction .getManager (), id , executorService );
204- dao ._delete ( id );
203+ dao .delete ( transaction . getManager (), id );
205204 ctx .status (204 );
206205 extensions .runPostDelete (ctx , transaction .getManager (), id , executorService );
207206
0 commit comments