Skip to content

Commit

Permalink
#80 allow sync callbacks after completion
Browse files Browse the repository at this point in the history
  • Loading branch information
aburmeis committed May 31, 2023
1 parent 7621639 commit 499fe1a
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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());
}
}

0 comments on commit 499fe1a

Please sign in to comment.