// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/TransactionManager.java
// public class TransactionManager {
// 
//     private final Logger logger = LoggerFactory.getLogger(TransactionManager.class);
// 
//     private TransactionConfigurator transactionConfigurator;
// 
//     public TransactionManager(TransactionConfigurator transactionConfigurator) {
//         this.transactionConfigurator = transactionConfigurator;
//     }
// 
//     private ThreadLocal<Transaction> threadLocalTransaction = new ThreadLocal<Transaction>();
// 
//     public void begin() {
//         logger.debug("transaction begin.");
//         Transaction transaction = new Transaction(TransactionType.ROOT);
//         TransactionRepository transactionRepository = transactionConfigurator.getTransactionRepository();
//         transactionRepository.create(transaction);
//         threadLocalTransaction.set(transaction);
//     }
// 
//     public void propagationNewBegin(TransactionContext transactionContext) {
//         Transaction transaction = new Transaction(transactionContext);
//         transactionConfigurator.getTransactionRepository().create(transaction);
//         threadLocalTransaction.set(transaction);
//     }
// 
//     public void propagationExistBegin(TransactionContext transactionContext) throws NoExistedTransactionException {
//         TransactionRepository transactionRepository = transactionConfigurator.getTransactionRepository();
//         Transaction transaction = transactionRepository.findByXid(transactionContext.getXid());
// 
//         if (transaction != null) {
//             transaction.changeStatus(TransactionStatus.valueOf(transactionContext.getStatus()));
//             threadLocalTransaction.set(transaction);
//         } else {
//             throw new NoExistedTransactionException();
//         }
//     }
// 
//     public void commit() {
//         Transaction transaction = getCurrentTransaction();
//         transaction.changeStatus(TransactionStatus.CONFIRMING);
//         transactionConfigurator.getTransactionRepository().update(transaction);
// 
//         try {
//             transaction.commit();
//             transactionConfigurator.getTransactionRepository().delete(transaction);
//         } catch (Throwable commitException) {
//             logger.error("Compensable transaction confirm failed.", commitException);
//             throw new ConfirmingException(commitException);
//         }
//     }
// 
//     public Transaction getCurrentTransaction() {
//         return threadLocalTransaction.get();
//     }
// 
//     public void rollback() {
//         Transaction transaction = getCurrentTransaction();
//         transaction.changeStatus(TransactionStatus.CANCELLING);
//         transactionConfigurator.getTransactionRepository().update(transaction);
// 
//         try {
//             transaction.rollback();
//             transactionConfigurator.getTransactionRepository().delete(transaction);
//         } catch (Throwable rollbackException) {
//             logger.error("Compensable transaction rollback failed.", rollbackException);
// 
//         }
//     }
// 
// 
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/TransactionRepository.java
// public interface TransactionRepository {
// 
//     int create(Transaction transaction);
// 
//     int update(Transaction transaction);
// 
//     int delete(Transaction transaction);
// 
//     Transaction findByXid(TransactionXid xid);
// 
//     List<Transaction> findAllUnmodifiedSince(Date date);
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/recover/RecoverConfig.java
// public interface RecoverConfig {
// 
//     //事务最多重试次数
//     public int getMaxRetryCount();
// 
//     //事务恢复时间范围,单位秒.
//     public int getRecoverDuration();
// 
//     //事务执行表达式.
//     public String getCronExpression();
// 
// }
// 
// Path: tcc-transaction-spring/src/main/java/org/pankai/tcctransaction/spring/recover/DefaultRecoverConfig.java
// public class DefaultRecoverConfig implements RecoverConfig {
// 
//     public static final RecoverConfig INSTANCE = new DefaultRecoverConfig();
// 
//     private int maxRetryCount = 30;
// 
//     private int recoverDuration = 120; //120 seconds.
// 
//     private String cronExpression = "0 */1 * * * ?";
// 
//     @Override
//     public int getMaxRetryCount() {
//         return maxRetryCount;
//     }
// 
//     @Override
//     public int getRecoverDuration() {
//         return recoverDuration;
//     }
// 
//     @Override
//     public String getCronExpression() {
//         return cronExpression;
//     }
// 
//     public void setMaxRetryCount(int maxRetryCount) {
//         this.maxRetryCount = maxRetryCount;
//     }
// 
//     public void setRecoverDuration(int recoverDuration) {
//         this.recoverDuration = recoverDuration;
//     }
// 
//     public void setCronExpression(String cronExpression) {
//         this.cronExpression = cronExpression;
//     }
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/support/TransactionConfigurator.java
// public interface TransactionConfigurator {
// 
//     public TransactionManager getTransactionManager();
// 
//     public TransactionRepository getTransactionRepository();
// 
//     public RecoverConfig getRecoverConfig();
// }


import org.pankai.tcctransaction.TransactionManager;
import org.pankai.tcctransaction.TransactionRepository;
import org.pankai.tcctransaction.recover.RecoverConfig;
import org.pankai.tcctransaction.spring.recover.DefaultRecoverConfig;
import org.pankai.tcctransaction.support.TransactionConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
package org.pankai.tcctransaction.spring.support;


/**
 * Created by pktczwd on 2016/12/7.
 */
public class TccTransactionConfigurator implements TransactionConfigurator {

    @Autowired
    private TransactionRepository transactionRepository;

    @Autowired(required = false)
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/TransactionManager.java
// public class TransactionManager {
// 
//     private final Logger logger = LoggerFactory.getLogger(TransactionManager.class);
// 
//     private TransactionConfigurator transactionConfigurator;
// 
//     public TransactionManager(TransactionConfigurator transactionConfigurator) {
//         this.transactionConfigurator = transactionConfigurator;
//     }
// 
//     private ThreadLocal<Transaction> threadLocalTransaction = new ThreadLocal<Transaction>();
// 
//     public void begin() {
//         logger.debug("transaction begin.");
//         Transaction transaction = new Transaction(TransactionType.ROOT);
//         TransactionRepository transactionRepository = transactionConfigurator.getTransactionRepository();
//         transactionRepository.create(transaction);
//         threadLocalTransaction.set(transaction);
//     }
// 
//     public void propagationNewBegin(TransactionContext transactionContext) {
//         Transaction transaction = new Transaction(transactionContext);
//         transactionConfigurator.getTransactionRepository().create(transaction);
//         threadLocalTransaction.set(transaction);
//     }
// 
//     public void propagationExistBegin(TransactionContext transactionContext) throws NoExistedTransactionException {
//         TransactionRepository transactionRepository = transactionConfigurator.getTransactionRepository();
//         Transaction transaction = transactionRepository.findByXid(transactionContext.getXid());
// 
//         if (transaction != null) {
//             transaction.changeStatus(TransactionStatus.valueOf(transactionContext.getStatus()));
//             threadLocalTransaction.set(transaction);
//         } else {
//             throw new NoExistedTransactionException();
//         }
//     }
// 
//     public void commit() {
//         Transaction transaction = getCurrentTransaction();
//         transaction.changeStatus(TransactionStatus.CONFIRMING);
//         transactionConfigurator.getTransactionRepository().update(transaction);
// 
//         try {
//             transaction.commit();
//             transactionConfigurator.getTransactionRepository().delete(transaction);
//         } catch (Throwable commitException) {
//             logger.error("Compensable transaction confirm failed.", commitException);
//             throw new ConfirmingException(commitException);
//         }
//     }
// 
//     public Transaction getCurrentTransaction() {
//         return threadLocalTransaction.get();
//     }
// 
//     public void rollback() {
//         Transaction transaction = getCurrentTransaction();
//         transaction.changeStatus(TransactionStatus.CANCELLING);
//         transactionConfigurator.getTransactionRepository().update(transaction);
// 
//         try {
//             transaction.rollback();
//             transactionConfigurator.getTransactionRepository().delete(transaction);
//         } catch (Throwable rollbackException) {
//             logger.error("Compensable transaction rollback failed.", rollbackException);
// 
//         }
//     }
// 
// 
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/TransactionRepository.java
// public interface TransactionRepository {
// 
//     int create(Transaction transaction);
// 
//     int update(Transaction transaction);
// 
//     int delete(Transaction transaction);
// 
//     Transaction findByXid(TransactionXid xid);
// 
//     List<Transaction> findAllUnmodifiedSince(Date date);
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/recover/RecoverConfig.java
// public interface RecoverConfig {
// 
//     //事务最多重试次数
//     public int getMaxRetryCount();
// 
//     //事务恢复时间范围,单位秒.
//     public int getRecoverDuration();
// 
//     //事务执行表达式.
//     public String getCronExpression();
// 
// }
// 
// Path: tcc-transaction-spring/src/main/java/org/pankai/tcctransaction/spring/recover/DefaultRecoverConfig.java
// public class DefaultRecoverConfig implements RecoverConfig {
// 
//     public static final RecoverConfig INSTANCE = new DefaultRecoverConfig();
// 
//     private int maxRetryCount = 30;
// 
//     private int recoverDuration = 120; //120 seconds.
// 
//     private String cronExpression = "0 */1 * * * ?";
// 
//     @Override
//     public int getMaxRetryCount() {
//         return maxRetryCount;
//     }
// 
//     @Override
//     public int getRecoverDuration() {
//         return recoverDuration;
//     }
// 
//     @Override
//     public String getCronExpression() {
//         return cronExpression;
//     }
// 
//     public void setMaxRetryCount(int maxRetryCount) {
//         this.maxRetryCount = maxRetryCount;
//     }
// 
//     public void setRecoverDuration(int recoverDuration) {
//         this.recoverDuration = recoverDuration;
//     }
// 
//     public void setCronExpression(String cronExpression) {
//         this.cronExpression = cronExpression;
//     }
// }
// 
// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/support/TransactionConfigurator.java
// public interface TransactionConfigurator {
// 
//     public TransactionManager getTransactionManager();
// 
//     public TransactionRepository getTransactionRepository();
// 
//     public RecoverConfig getRecoverConfig();
// }


// Path: tcc-transaction-spring/src/main/java/org/pankai/tcctransaction/spring/support/TccTransactionConfigurator.java
import org.pankai.tcctransaction.TransactionManager;
import org.pankai.tcctransaction.TransactionRepository;
import org.pankai.tcctransaction.recover.RecoverConfig;
import org.pankai.tcctransaction.spring.recover.DefaultRecoverConfig;
import org.pankai.tcctransaction.support.TransactionConfigurator;
import org.springframework.beans.factory.annotation.Autowired;

package org.pankai.tcctransaction.spring.support;


/**
 * Created by pktczwd on 2016/12/7.
 */
public class TccTransactionConfigurator implements TransactionConfigurator {

    @Autowired
    private TransactionRepository transactionRepository;

    @Autowired(required = false)
    private RecoverConfig recoverConfig = DefaultRecoverConfig.INSTANCE;