Class TransactionExecutor


  • @Service
    public class TransactionExecutor
    extends Object
    A utility that executes transactions with optional rollback.
    • Constructor Detail

      • TransactionExecutor

        public TransactionExecutor()
    • Method Detail

      • executeWithRollbackOption

        @Async
        public <T> org.springframework.util.concurrent.ListenableFuture<T> executeWithRollbackOption​(Supplier<T> supplier,
                                                                                                     AtomicBoolean shouldRollback)
        Executes the given supplier in a transaction, allowing the caller to trigger rollback before its completion by setting the provided flag.
        Type Parameters:
        T - the return type of the function
        Parameters:
        supplier - the function to execute
        shouldRollback - a flag indicating whether the transaction should be rolled back once the function has been executed
        Returns:
        the value returned by the supplier