Как добавить синхронизацию в Atomikos TransactionStateHandler - PullRequest
0 голосов
/ 12 ноября 2018

Как я могу добавить синхронизацию в TransactionStateHandler в atomikos? По умолчанию это просто JdbcRequeueSynchronization, который получил пустой beforeCompletion метод

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;
}

1 Ответ

0 голосов
/ 01 декабря 2018

Вы можете сделать это через объект Transaction (в 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

Надеюсь, что поможет

Guy

...