nl.vpro.services.TransactionService Maven / Gradle / Ivy
package nl.vpro.services;
import java.util.concurrent.Callable;
import java.util.function.*;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.meeuw.functional.ThrowAnyRunnable;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* Please note that transactions are only rolled back in case of a runtime exception
*
* Also note that in new transactions the currently existing hibernate filters will be gone.
*
* @author Danny Sedney
*/
public interface TransactionService {
/**
* Run callable in new transaction. Transaction is rolled back ONLY in case of a runtime exception
* @param callable The jobs to be processed in the new transaction
* @return The result of the callable
* @throws Exception The exception thrown by the callable
*/
T executeInNewTransaction(@NonNull Callable callable) throws Exception;
T getInNewTransaction(@NonNull Supplier supplier);
T getInTransaction(@NonNull Supplier supplier);
void executeInNewTransaction(@NonNull Runnable runnable);
T executeInNewTransaction(S argument, @NonNull Function function);
void executeInNewTransaction(T argument,@NonNull Consumer consumer);
T executeInReadonlyTransaction(@NonNull Callable callable) throws Exception;
T getInReadonlyTransaction(@NonNull Supplier supplier);
void executeInReadonlyTransaction(@NonNull ThrowAnyRunnable runnable);
void executeInReadonlyTransaction(@NonNull Runnable runnable);
T executeInReadonlyTransaction(S argument, @NonNull Function function);
void executeInReadonlyTransaction(T argument, @NonNull Consumer consumer);
@Transactional(propagation = Propagation.NEVER)
default void ensureNoTransaction() {
}
}