@@ -286,8 +286,12 @@ private SqlConnection client() {
286
286
287
287
@ Override
288
288
public CompletionStage <Void > beginTransaction () {
289
+ if ( transaction != null ) {
290
+ throw new IllegalStateException ( "Can't begin a new transaction as an active transaction is already associated to this connection" );
291
+ }
289
292
return connection .begin ()
290
293
.onSuccess ( tx -> LOG .tracef ( "Transaction started: %s" , tx ) )
294
+ .onFailure ( v -> LOG .errorf ( "Failed to start a transaction: %s" , transaction ) )
291
295
.toCompletionStage ()
292
296
.thenAccept ( this ::setTransaction );
293
297
}
@@ -296,22 +300,28 @@ public CompletionStage<Void> beginTransaction() {
296
300
public CompletionStage <Void > commitTransaction () {
297
301
return transaction .commit ()
298
302
.onSuccess ( v -> LOG .tracef ( "Transaction committed: %s" , transaction ) )
303
+ .onFailure ( v -> LOG .errorf ( "Failed to commit transaction: %s" , transaction ) )
299
304
.toCompletionStage ()
300
305
.whenComplete ( this ::clearTransaction );
301
306
}
302
307
303
308
@ Override
304
309
public CompletionStage <Void > rollbackTransaction () {
305
310
return transaction .rollback ()
311
+ .onFailure ( v -> LOG .errorf ( "Failed to rollback transaction: %s" , transaction ) )
306
312
.onSuccess ( v -> LOG .tracef ( "Transaction rolled back: %s" , transaction ) )
307
313
.toCompletionStage ()
308
314
.whenComplete ( this ::clearTransaction );
309
315
}
310
316
311
317
@ Override
312
318
public CompletionStage <Void > close () {
319
+ if ( transaction != null ) {
320
+ throw new IllegalStateException ( "Connection being closed with a live transaction associated to it" );
321
+ }
313
322
return connection .close ()
314
323
.onSuccess ( event -> LOG .tracef ( "Connection closed: %s" , connection ) )
324
+ .onFailure ( v -> LOG .errorf ( "Failed to close a connection: %s" , connection ) )
315
325
.toCompletionStage ();
316
326
}
317
327
@@ -357,6 +367,7 @@ private void setTransaction(Transaction tx) {
357
367
}
358
368
359
369
private void clearTransaction (Void v , Throwable x ) {
370
+ LOG .tracef ( "Clearing current transaction instance from connection: %s" , transaction );
360
371
transaction = null ;
361
372
}
362
373
0 commit comments