package cn.axzo.msg.center.inside.notices.utils;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.function.Supplier;

/**
 * @author yanglin
 */
@Component
@RequiredArgsConstructor
public class FunctionalTransactionTemplate {

    private final TransactionTemplate transactionTemplate;

    public void exec(Runnable action) {
        transactionTemplate.executeWithoutResult(unused -> action.run());
    }

    public <T> void exec(Supplier<T> supplier) {
        transactionTemplate.execute(unused -> supplier.get());
    }

}