From 499fe1afd5068c2c1aa542dc8737b0cb63a3f1ff Mon Sep 17 00:00:00 2001 From: Arne Burmeister Date: Thu, 16 Mar 2023 16:38:50 +0100 Subject: [PATCH] #80 allow sync callbacks after completion --- .../transaction/ArangoTransactionManager.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java index 862aaffc8..ca96b3cc4 100644 --- a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java +++ b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java @@ -54,8 +54,8 @@ public class ArangoTransactionManager extends AbstractPlatformTransactionManager public ArangoTransactionManager(ArangoOperations operations, QueryTransactionBridge bridge) { this.operations = operations; this.bridge = bridge; - super.setGlobalRollbackOnParticipationFailure(true); - super.setTransactionSynchronization(SYNCHRONIZATION_ON_ACTUAL_TRANSACTION); + setGlobalRollbackOnParticipationFailure(true); + setTransactionSynchronization(SYNCHRONIZATION_ON_ACTUAL_TRANSACTION); } /** @@ -126,10 +126,21 @@ protected void doCommit(DefaultTransactionStatus status) throws TransactionExcep } try { tx.commit(); + afterCompletion(); } catch (ArangoDBException error) { + if (!isRollbackOnCommitFailure()) { + try { + tx.rollback(); + } catch (ArangoDBException noRollback) { + if (logger.isDebugEnabled()) { + logger.debug("Cannot rollback after commit " + tx, noRollback); + } + // expose commit exception instead + } finally { + afterCompletion(); + } + } throw new TransactionSystemException("Cannot commit transaction " + tx, error); - } finally { - bridge.clearCurrentTransaction(); } } @@ -151,7 +162,7 @@ protected void doRollback(DefaultTransactionStatus status) throws TransactionExc } catch (ArangoDBException error) { throw new TransactionSystemException("Cannot roll back transaction " + tx, error); } finally { - bridge.clearCurrentTransaction(); + afterCompletion(); } } @@ -203,13 +214,8 @@ protected void prepareSynchronization(DefaultTransactionStatus status, Transacti } } - /** - * Unbind the holder from the last transaction completed. - * - * @see ArangoTransactionHolder - */ - @Override - protected void doCleanupAfterCompletion(Object transaction) { + private void afterCompletion() { + bridge.clearCurrentTransaction(); TransactionSynchronizationManager.unbindResource(operations.getDatabaseName()); } }