Example usage for org.springframework.transaction.reactive TransactionSynchronizationManager getSynchronizations

List of usage examples for org.springframework.transaction.reactive TransactionSynchronizationManager getSynchronizations

Introduction

In this page you can find the example usage for org.springframework.transaction.reactive TransactionSynchronizationManager getSynchronizations.

Prototype

public List<TransactionSynchronization> getSynchronizations() throws IllegalStateException 

Source Link

Document

Return an unmodifiable snapshot list of all registered synchronizations for the current context.

Usage

From source file:org.springframework.transaction.reactive.AbstractReactiveTransactionManager.java

/**
 * Suspend all current synchronizations and deactivate transaction
 * synchronization for the current transaction context.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @return the List of suspended TransactionSynchronization objects
 *//*from  w  w w. j  av a2  s  .  c om*/
private Mono<List<TransactionSynchronization>> doSuspendSynchronization(
        TransactionSynchronizationManager synchronizationManager) {

    List<TransactionSynchronization> suspendedSynchronizations = synchronizationManager.getSynchronizations();
    return Flux.fromIterable(suspendedSynchronizations).concatMap(TransactionSynchronization::suspend)
            .then(Mono.defer(() -> {
                synchronizationManager.clearSynchronization();
                return Mono.just(suspendedSynchronizations);
            }));
}

From source file:org.springframework.transaction.reactive.AbstractReactiveTransactionManager.java

/**
 * Trigger {@code beforeCommit} callbacks.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @param status object representing the transaction
 *//*w  ww. j ava2 s. c  om*/
private Mono<Void> triggerBeforeCommit(TransactionSynchronizationManager synchronizationManager,
        GenericReactiveTransaction status) {

    if (status.isNewSynchronization()) {
        if (status.isDebug()) {
            logger.trace("Triggering beforeCommit synchronization");
        }
        return TransactionSynchronizationUtils.triggerBeforeCommit(synchronizationManager.getSynchronizations(),
                status.isReadOnly());
    }

    return Mono.empty();
}

From source file:org.springframework.transaction.reactive.AbstractReactiveTransactionManager.java

/**
 * Trigger {@code beforeCompletion} callbacks.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @param status object representing the transaction
 */// ww w. ja v a  2  s.c om
private Mono<Void> triggerBeforeCompletion(TransactionSynchronizationManager synchronizationManager,
        GenericReactiveTransaction status) {

    if (status.isNewSynchronization()) {
        if (status.isDebug()) {
            logger.trace("Triggering beforeCompletion synchronization");
        }
        return TransactionSynchronizationUtils
                .triggerBeforeCompletion(synchronizationManager.getSynchronizations());
    }

    return Mono.empty();
}

From source file:org.springframework.transaction.reactive.AbstractReactiveTransactionManager.java

/**
 * Trigger {@code afterCommit} callbacks.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @param status object representing the transaction
 *//*from  w  w w . j  a v a  2s  . c  o  m*/
private Mono<Void> triggerAfterCommit(TransactionSynchronizationManager synchronizationManager,
        GenericReactiveTransaction status) {

    if (status.isNewSynchronization()) {
        if (status.isDebug()) {
            logger.trace("Triggering afterCommit synchronization");
        }
        return TransactionSynchronizationUtils.invokeAfterCommit(synchronizationManager.getSynchronizations());
    }

    return Mono.empty();
}

From source file:org.springframework.transaction.reactive.AbstractReactiveTransactionManager.java

/**
 * Trigger {@code afterCompletion} callbacks.
 * @param synchronizationManager the synchronization manager bound to the current transaction
 * @param status object representing the transaction
 * @param completionStatus completion status according to TransactionSynchronization constants
 *//*w  w w. j a v  a2  s .c o  m*/
private Mono<Void> triggerAfterCompletion(TransactionSynchronizationManager synchronizationManager,
        GenericReactiveTransaction status, int completionStatus) {

    if (status.isNewSynchronization()) {
        List<TransactionSynchronization> synchronizations = synchronizationManager.getSynchronizations();
        synchronizationManager.clearSynchronization();
        if (!status.hasTransaction() || status.isNewTransaction()) {
            if (status.isDebug()) {
                logger.trace("Triggering afterCompletion synchronization");
            }
            // No transaction or new transaction for the current scope ->
            // invoke the afterCompletion callbacks immediately
            return invokeAfterCompletion(synchronizationManager, synchronizations, completionStatus);
        } else if (!synchronizations.isEmpty()) {
            // Existing transaction that we participate in, controlled outside
            // of the scope of this Spring transaction manager -> try to register
            // an afterCompletion callback with the existing (JTA) transaction.
            return registerAfterCompletionWithExistingTransaction(synchronizationManager,
                    status.getTransaction(), synchronizations);
        }
    }

    return Mono.empty();
}