package com.sptg.common.core.cfgbeans;

import com.codingapi.txlcn.common.util.Transactions;
import com.codingapi.txlcn.tc.aspect.interceptor.TxLcnInterceptor;
import com.codingapi.txlcn.tc.aspect.weave.DTXLogicWeaver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * title: AopTypeDTXConfiguration
 * package: com.cjlgb.tx.clent.cfgbeans
 * description:
 *
 *                  
 *                
 */
@Configuration
public class AopTypeDtxConfigBean {


    /**
     * 分布式事务配置 设置为LCN模式
     */
    @Bean
    @ConditionalOnBean(DTXLogicWeaver.class)
    public TxLcnInterceptor txLcnInterceptor(@Autowired DTXLogicWeaver dtxLogicWeaver) {
        TxLcnInterceptor txLcnInterceptor = new TxLcnInterceptor(dtxLogicWeaver);
        Properties properties = new Properties();
        properties.setProperty(Transactions.DTX_TYPE, Transactions.LCN);
        properties.setProperty(Transactions.DTX_PROPAGATION, "REQUIRED");
        txLcnInterceptor.setTransactionAttributes(properties);
        return txLcnInterceptor;
    }

}
