@@ -182,7 +182,7 @@ else if ( state.value == State.ROLLED_BACK )
182
182
{
183
183
return resultCursors .retrieveNotConsumedError ()
184
184
.thenCompose ( error -> doCommitAsync ( error ).handle ( handleCommitOrRollback ( error ) ) )
185
- .whenComplete ( ( ignore , error ) -> handleTransactionCompletion ( State . COMMITTED , error ) );
185
+ .whenComplete ( ( ignore , error ) -> handleTransactionCompletion ( true , error ) );
186
186
}
187
187
}
188
188
@@ -200,7 +200,7 @@ else if ( state.value == State.ROLLED_BACK )
200
200
{
201
201
return resultCursors .retrieveNotConsumedError ()
202
202
.thenCompose ( error -> doRollbackAsync ().handle ( handleCommitOrRollback ( error ) ) )
203
- .whenComplete ( ( ignore , error ) -> handleTransactionCompletion ( State . ROLLED_BACK , error ) );
203
+ .whenComplete ( ( ignore , error ) -> handleTransactionCompletion ( false , error ) );
204
204
}
205
205
}
206
206
@@ -287,16 +287,24 @@ private static BiFunction<Void,Throwable,Void> handleCommitOrRollback( Throwable
287
287
};
288
288
}
289
289
290
- private void handleTransactionCompletion ( State onSuccessState , Throwable throwable )
290
+ private void handleTransactionCompletion ( boolean commitOnSuccess , Throwable throwable )
291
291
{
292
+ if ( commitOnSuccess && throwable == null )
293
+ {
294
+ state = StateHolder .of ( State .COMMITTED );
295
+ }
296
+ else
297
+ {
298
+ state = StateHolder .of ( State .ROLLED_BACK );
299
+ }
300
+
292
301
if ( throwable instanceof AuthorizationExpiredException )
293
302
{
294
- markTerminated ( throwable );
295
303
connection .terminateAndRelease ( AuthorizationExpiredException .DESCRIPTION );
296
- return ;
297
304
}
298
-
299
- state = StateHolder .of ( onSuccessState );
300
- connection .release (); // release in background
305
+ else
306
+ {
307
+ connection .release (); // release in background
308
+ }
301
309
}
302
310
}
0 commit comments