@@ -166,10 +166,9 @@ public void updateCollectionWithDuplicatesWithStageAPI(TestContext context) {
166
166
167
167
Person thomas = new Person ( 47 , "Thomas Reaper" , phones );
168
168
169
- test ( context , openSession ()
170
- .thenCompose ( session -> session
171
- .persist ( thomas )
172
- .thenCompose ( v -> session .flush () ) )
169
+ test ( context , getSessionFactory ()
170
+ .withTransaction ( (session , tx ) -> session
171
+ .persist ( thomas ) )
173
172
.thenCompose ( v -> openSession () )
174
173
.thenCompose ( session -> session
175
174
.find ( Person .class , thomas .getId () )
@@ -196,12 +195,12 @@ public void updateCollectionWithDuplicatesWithMutinyAPI(TestContext context) {
196
195
197
196
Person thomas = new Person ( 47 , "Thomas Reaper" , phones );
198
197
199
- test ( context , openMutinySession ()
200
- .chain ( session -> session
201
- .persist ( thomas )
202
- .call ( session ::flush ) )
198
+ test ( context , getMutinySessionFactory ()
199
+ .withTransaction ( (session , tx ) -> session
200
+ .persist ( thomas ) )
203
201
.chain ( () -> openMutinySession () )
204
- .chain ( newSession -> newSession .find ( Person .class , thomas .getId () )
202
+ .chain ( newSession -> newSession
203
+ .find ( Person .class , thomas .getId () )
205
204
// Change a couple of the elements in the collection
206
205
.invoke ( found -> {
207
206
found .getPhones ().set ( 1 , new Phone ( "47" ) );
@@ -224,10 +223,9 @@ public void deleteElementsFromCollectionWithDuplicatesWithStageAPI(TestContext c
224
223
225
224
Person thomas = new Person ( 47 , "Thomas Reaper" , phones );
226
225
227
- test ( context , openSession ()
228
- .thenCompose ( session -> session
229
- .persist ( thomas )
230
- .thenCompose ( v -> session .flush () ) )
226
+ test ( context , getSessionFactory ()
227
+ .withTransaction ( (session , tx ) -> session
228
+ .persist ( thomas ) )
231
229
.thenCompose ( v -> openSession () )
232
230
.thenCompose ( newSession -> newSession
233
231
.find ( Person .class , thomas .getId () )
@@ -254,10 +252,9 @@ public void deleteElementsFromCollectionWithDuplicatesWithMutinyAPI(TestContext
254
252
255
253
Person thomas = new Person ( 47 , "Thomas Reaper" , phones );
256
254
257
- test ( context , openMutinySession ()
258
- .chain ( session -> session
259
- .persist ( thomas )
260
- .call ( session ::flush ) )
255
+ test ( context , getMutinySessionFactory ()
256
+ .withTransaction ( (session , tx ) -> session
257
+ .persist ( thomas ) )
261
258
.chain ( this ::openMutinySession )
262
259
.chain ( newSession -> newSession
263
260
.find ( Person .class , thomas .getId () )
@@ -276,12 +273,11 @@ public void deleteElementsFromCollectionWithDuplicatesWithMutinyAPI(TestContext
276
273
277
274
@ Test
278
275
public void addOneElementWithMutinyAPI (TestContext context ) {
279
- test ( context , openMutinySession ()
280
- .chain ( session -> session
276
+ test ( context , getMutinySessionFactory ()
277
+ .withTransaction ( ( session , tx ) -> session
281
278
.find ( Person .class , thePerson .getId () )
282
279
// add one element to the collection
283
- .invoke ( foundPerson -> foundPerson .getPhones ().add ( new Phone ( "000" ) ) )
284
- .call ( session ::flush ) )
280
+ .invoke ( foundPerson -> foundPerson .getPhones ().add ( new Phone ( "000" ) ) ) )
285
281
// Check new person collection
286
282
.chain ( this ::openMutinySession )
287
283
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
@@ -291,12 +287,11 @@ public void addOneElementWithMutinyAPI(TestContext context) {
291
287
292
288
@ Test
293
289
public void removeOneElementWithStageAPI (TestContext context ) {
294
- test ( context , openSession ()
295
- .thenCompose ( session -> session
290
+ test ( context , getSessionFactory ()
291
+ .withTransaction ( ( session , tx ) -> session
296
292
.find ( Person .class , thePerson .getId () )
297
293
// Remove one element from the collection
298
- .thenAccept ( foundPerson -> foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) ) )
299
- .thenCompose ( v -> session .flush () ) )
294
+ .thenAccept ( foundPerson -> foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) ) ) )
300
295
.thenCompose ( v -> openSession () )
301
296
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
302
297
.thenAccept ( foundPerson -> assertPhones ( context , foundPerson , "111-111-1111" ) )
@@ -305,12 +300,11 @@ public void removeOneElementWithStageAPI(TestContext context) {
305
300
306
301
@ Test
307
302
public void removeOneElementWithMutinyAPI (TestContext context ) {
308
- test ( context , openMutinySession ()
309
- .chain ( session -> session
303
+ test ( context , getMutinySessionFactory ()
304
+ .withTransaction ( ( session , tx ) -> session
310
305
.find ( Person .class , thePerson .getId () )
311
306
// Remove one element from the collection
312
- .invoke ( foundPerson -> foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) ) )
313
- .call ( session ::flush ) )
307
+ .invoke ( foundPerson -> foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) ) ) )
314
308
.chain ( this ::openMutinySession )
315
309
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
316
310
.invoke ( foundPerson -> assertPhones ( context , foundPerson , "111-111-1111" ) )
@@ -319,12 +313,11 @@ public void removeOneElementWithMutinyAPI(TestContext context) {
319
313
320
314
@ Test
321
315
public void clearCollectionElementsStageAPI (TestContext context ) {
322
- test ( context , openSession ()
323
- .thenCompose ( session -> session
316
+ test ( context , getSessionFactory ()
317
+ .withTransaction ( ( session , tx ) -> session
324
318
.find ( Person .class , thePerson .getId () )
325
319
// clear collection
326
- .thenAccept ( foundPerson -> foundPerson .getPhones ().clear () )
327
- .thenCompose ( v -> session .flush () ) )
320
+ .thenAccept ( foundPerson -> foundPerson .getPhones ().clear () ) )
328
321
.thenCompose ( s -> openSession () )
329
322
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
330
323
.thenAccept ( changedPerson -> assertPhones ( context , changedPerson ) )
@@ -333,12 +326,11 @@ public void clearCollectionElementsStageAPI(TestContext context) {
333
326
334
327
@ Test
335
328
public void clearCollectionElementsMutinyAPI (TestContext context ) {
336
- test ( context , openMutinySession ()
337
- .chain ( session -> session
329
+ test ( context , getMutinySessionFactory ()
330
+ .withTransaction ( ( session , tx ) -> session
338
331
.find ( Person .class , thePerson .getId () )
339
332
// clear collection
340
- .invoke ( foundPerson -> foundPerson .getPhones ().clear () )
341
- .call ( session ::flush ) )
333
+ .invoke ( foundPerson -> foundPerson .getPhones ().clear () ) )
342
334
.chain ( this ::openMutinySession )
343
335
.chain ( session -> session .find ( Person .class , thePerson .getId () )
344
336
.invoke ( changedPerson -> context .assertTrue ( changedPerson .getPhones ().isEmpty () ) ) )
@@ -347,15 +339,14 @@ public void clearCollectionElementsMutinyAPI(TestContext context) {
347
339
348
340
@ Test
349
341
public void removeAndAddElementWithStageAPI (TestContext context ){
350
- test ( context , openSession ()
351
- .thenCompose ( session -> session
342
+ test ( context , getSessionFactory ()
343
+ .withTransaction ( ( session , tx ) -> session
352
344
.find ( Person .class , thePerson .getId () )
353
345
.thenAccept ( foundPerson -> {
354
346
context .assertNotNull ( foundPerson );
355
347
foundPerson .getPhones ().remove ( new Phone ( "111-111-1111" ) );
356
348
foundPerson .getPhones ().add ( new Phone ( "000" ) );
357
- } )
358
- .thenCompose ( v -> session .flush () ) )
349
+ } ) )
359
350
.thenCompose ( v -> openSession () )
360
351
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
361
352
.thenAccept ( changedPerson -> assertPhones ( context , changedPerson , "000" , "999-999-9999" ) )
@@ -364,15 +355,14 @@ public void removeAndAddElementWithStageAPI(TestContext context){
364
355
365
356
@ Test
366
357
public void removeAndAddElementWithMutinyAPI (TestContext context ){
367
- test ( context , openMutinySession ()
368
- .chain ( session -> session
358
+ test ( context , getMutinySessionFactory ()
359
+ .withTransaction ( ( session , tx ) -> session
369
360
.find ( Person .class , thePerson .getId () )
370
361
.invoke ( foundPerson -> {
371
362
context .assertNotNull ( foundPerson );
372
363
foundPerson .getPhones ().remove ( new Phone ( "111-111-1111" ) );
373
364
foundPerson .getPhones ().add ( new Phone ( "000" ) );
374
- } )
375
- .call ( session ::flush ) )
365
+ } ) )
376
366
.chain ( () -> openMutinySession () )
377
367
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
378
368
.invoke ( person -> assertPhones ( context , person , "000" , "999-999-9999" ) )
@@ -381,15 +371,14 @@ public void removeAndAddElementWithMutinyAPI(TestContext context){
381
371
382
372
@ Test
383
373
public void replaceSecondCollectionElementStageAPI (TestContext context ){
384
- test ( context , openSession ()
385
- .thenCompose ( session -> session
374
+ test ( context , getSessionFactory ()
375
+ .withTransaction ( ( session , tx ) -> session
386
376
.find ( Person .class , thePerson .getId () )
387
377
.thenAccept ( foundPerson -> {
388
378
// remove existing phone and add new phone
389
379
foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) );
390
380
foundPerson .getPhones ().add ( new Phone ( "000-000-0000" ) );
391
- } )
392
- .thenCompose ( v -> session .flush () ) )
381
+ } ) )
393
382
.thenCompose ( s -> openSession () )
394
383
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
395
384
.thenAccept ( changedPerson -> assertPhones ( context , changedPerson , "000-000-0000" , "111-111-1111" ) )
@@ -398,15 +387,14 @@ public void replaceSecondCollectionElementStageAPI(TestContext context){
398
387
399
388
@ Test
400
389
public void replaceSecondCollectionElementMutinyAPI (TestContext context ){
401
- test ( context , openMutinySession ()
402
- .chain ( session -> session
390
+ test ( context , getMutinySessionFactory ()
391
+ .withTransaction ( ( session , tx ) -> session
403
392
.find ( Person .class , thePerson .getId () )
404
393
.invoke ( foundPerson -> {
405
394
// remove existing phone and add new phone
406
395
foundPerson .getPhones ().remove ( new Phone ( "999-999-9999" ) );
407
396
foundPerson .getPhones ().add ( new Phone ( "000-000-0000" ) );
408
- } )
409
- .call ( session ::flush ) )
397
+ } ) )
410
398
.chain ( () -> openMutinySession () )
411
399
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
412
400
.invoke ( changedPerson -> assertPhones ( context , changedPerson , "000-000-0000" , "111-111-1111" ) )
@@ -415,12 +403,11 @@ public void replaceSecondCollectionElementMutinyAPI(TestContext context){
415
403
416
404
@ Test
417
405
public void setNewElementCollectionStageAPI (TestContext context ) {
418
- test ( context , openSession ()
419
- .thenCompose ( session -> session
406
+ test ( context , getSessionFactory ()
407
+ .withTransaction ( ( session , tx ) -> session
420
408
.find ( Person .class , thePerson .getId () )
421
409
// replace phones with list of 1 phone
422
- .thenAccept ( foundPerson -> foundPerson .setPhones ( Arrays .asList ( new Phone ( "000-000-0000" ) ) ) )
423
- .thenCompose ( v -> session .flush () ) )
410
+ .thenAccept ( foundPerson -> foundPerson .setPhones ( Arrays .asList ( new Phone ( "000-000-0000" ) ) ) ) )
424
411
.thenCompose ( s -> openSession () )
425
412
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
426
413
.thenAccept ( changedPerson -> assertPhones ( context , changedPerson , "000-000-0000" ) )
@@ -429,12 +416,11 @@ public void setNewElementCollectionStageAPI(TestContext context) {
429
416
430
417
@ Test
431
418
public void setNewElementCollectionMutinyAPI (TestContext context ) {
432
- test ( context , openMutinySession ()
433
- .chain ( session -> session
419
+ test ( context , getMutinySessionFactory ()
420
+ .withTransaction ( ( session , tx ) -> session
434
421
.find ( Person .class , thePerson .getId () )
435
422
// replace phones with list of 1 phone
436
- .invoke ( foundPerson -> foundPerson .setPhones ( Arrays .asList ( new Phone ( "000-000-0000" ) ) ) )
437
- .call ( session ::flush ) )
423
+ .invoke ( foundPerson -> foundPerson .setPhones ( Arrays .asList ( new Phone ( "000-000-0000" ) ) ) ) )
438
424
.chain ( this ::openMutinySession )
439
425
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
440
426
.invoke ( changedPerson -> assertPhones ( context , changedPerson , "000-000-0000" ) )
@@ -443,12 +429,11 @@ public void setNewElementCollectionMutinyAPI(TestContext context) {
443
429
444
430
@ Test
445
431
public void removePersonStageAPI (TestContext context ){
446
- test ( context , openSession ()
447
- .thenCompose ( session -> session
432
+ test ( context , getSessionFactory ()
433
+ .withTransaction ( ( session , tx ) -> session
448
434
.find ( Person .class , thePerson .getId () )
449
435
// remove thePerson entity and flush
450
- .thenCompose ( foundPerson -> session .remove ( foundPerson ) )
451
- .thenCompose ( v -> session .flush () ) )
436
+ .thenCompose ( foundPerson -> session .remove ( foundPerson ) ) )
452
437
.thenCompose ( v -> openSession () )
453
438
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
454
439
.thenAccept ( context ::assertNull )
@@ -460,12 +445,11 @@ public void removePersonStageAPI(TestContext context){
460
445
461
446
@ Test
462
447
public void removePersonMutinyAPI (TestContext context ) {
463
- test ( context , openMutinySession ()
464
- .chain ( session -> session
448
+ test ( context , getMutinySessionFactory ()
449
+ .withTransaction ( ( session , tx ) -> session
465
450
.find ( Person .class , thePerson .getId () )
466
451
// remove thePerson entity and flush
467
- .call ( session ::remove )
468
- .call ( session ::flush ) )
452
+ .call ( session ::remove ) )
469
453
.chain ( this ::openMutinySession )
470
454
.chain ( session -> session .find ( Person .class , thePerson .getId () ) )
471
455
.invoke ( context ::assertNull )
0 commit comments