0

How I can add synchronization to TransactionStateHandler in atomikos ? Default this contains just JdbcRequeueSynchronization which got empty beforeCompletion method

private Throwable notifyBeforeCompletion() {
    Throwable cause = null;
    Synchronization sync = localPopSynchronization();
    while ( sync != null ) {
        try {
            sync.beforeCompletion ();
        } catch ( RuntimeException error ) {
            // see case 24246: rollback only
            setRollbackOnly();
            // see case 115604
            // transport the first exception here as return value
            if (cause == null) {
                cause = error;
            } else {
                // log the others which may still happen as error - cf. case 115604
                LOGGER.logError("Unexpected error in beforeCompletion: ", error);
            }               
        }
        sync = localPopSynchronization();
    }
    return cause;
}
hudi
  • 15,555
  • 47
  • 142
  • 246

1 Answers1

0

You can do this via the Transaction object (in the JTA API):

UserTransactionManager utm = new UserTransactionManager();
utm.begin(); //optional, skip if you already have a transaction
Transaction tx = utm.getTransaction();
tx.registerSynchronization(...);
...
//commit / rollback per your requirements

Hope that helps

Guy

Guy Pardon
  • 484
  • 2
  • 8