// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/Transaction.java
// public class Transaction implements Serializable {
// 
//     private static final Logger logger = LoggerFactory.getLogger(Transaction.class);
// 
//     private TransactionXid xid;
//     private TransactionStatus status;
//     private TransactionType transactionType;
//     private volatile int retriedCount = 0;
//     private Date createTime = new Date();
//     private Date lastUpdateTime = new Date();
//     private long version = 1;
// 
//     private List<Participant> participants = new ArrayList<>();
// 
//     private Map<String, Object> attachments = new ConcurrentHashMap<>();
// 
//     public Transaction() {
//     }
// 
//     public Transaction(TransactionContext transactionContext) {
//         this.xid = transactionContext.getXid();
//         this.status = TransactionStatus.TRYING;
//         this.transactionType = TransactionType.BRANCH;
//     }
// 
//     public Transaction(TransactionType transactionType) {
//         this.xid = new TransactionXid();
//         this.status = TransactionStatus.TRYING;
//         this.transactionType = transactionType;
//     }
// 
//     public void enlistParticipant(Participant participant) {
//         //logging......start
//         logger.debug("Enlist participant.");
//         Terminator terminator = participant.getTerminator();
//         if (terminator != null) {
//             logger.debug("Confirm class is:" + terminator.getConfirmInvocationContext().getTargetClass().getName());
//             logger.debug("Confirm method is:" + terminator.getConfirmInvocationContext().getMethodName());
//             logger.debug("Cancel class is:" + terminator.getCancelInvocationContext().getTargetClass().getName());
//             logger.debug("Cancel method is:" + terminator.getCancelInvocationContext().getMethodName());
//         }
//         //logging......end
//         participants.add(participant);
//     }
// 
//     public Xid getXid() {
//         return xid.clone();
//     }
// 
//     public TransactionStatus getStatus() {
//         return status;
//     }
// 
//     public List<Participant> getParticipants() {
//         return Collections.unmodifiableList(participants);
//     }
// 
//     public TransactionType getTransactionType() {
//         return transactionType;
//     }
// 
//     public void changeStatus(TransactionStatus status) {
//         this.status = status;
//     }
// 
//     public void commit() {
//         for (Participant participant : participants) {
//             participant.commit();
//         }
//     }
// 
//     public void rollback() {
//         for (Participant participant : participants) {
//             participant.rollback();
//         }
//     }
// 
//     public int getRetriedCount() {
//         return retriedCount;
//     }
// 
//     public void addRetriedCount() {
//         this.retriedCount++;
//     }
// 
//     public void resetRetriedCount(int retriedCount) {
//         this.retriedCount = retriedCount;
//     }
// 
//     public Map<String, Object> getAttachments() {
//         return attachments;
//     }
// 
//     public long getVersion() {
//         return version;
//     }
// 
//     public void updateVersion() {
//         this.version++;
//     }
// 
//     public void setVersion(long version) {
//         this.version = version;
//     }
// 
//     public Date getLastUpdateTime() {
//         return lastUpdateTime;
//     }
// 
//     public void setLastUpdateTime(Date date) {
//         this.lastUpdateTime = date;
//     }
// 
//     public Date getCreateTime() {
//         return createTime;
//     }
// 
//     public void updateTime() {
//         this.lastUpdateTime = new Date();
//     }
// 
// }
// 
// 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-api/src/main/java/org/pankai/tcctransaction/api/TransactionStatus.java
// public enum TransactionStatus {
// 
//     TRYING(1), CONFIRMING(2), CANCELLING(3);
// 
// 
//     private int id;
// 
//     TransactionStatus(int id) {
//         this.id = id;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public static TransactionStatus valueOf(int id) {
//         switch (id) {
//             case 1:
//                 return TRYING;
//             case 2:
//                 return CONFIRMING;
//             default:
//                 return CANCELLING;
//         }
// 
//     }
// }
// 
// 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.Transaction;
import org.pankai.tcctransaction.TransactionRepository;
import org.pankai.tcctransaction.api.TransactionStatus;
import org.pankai.tcctransaction.support.TransactionConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
package org.pankai.tcctransaction.recover;



/**
 * 事务恢复器.当事务在指定的时间内未有状态变化时,会根据其上下文来决定提交,回滚或者是需要人工干预.
 * 可以在这里拓展需要人工干预时的通知.
 * Created by pktczwd on 2016/12/7.
 */
public class TransactionRecovery {

    private final Logger logger = LoggerFactory.getLogger(TransactionRecovery.class);

// Path: tcc-transaction-core/src/main/java/org/pankai/tcctransaction/Transaction.java
// public class Transaction implements Serializable {
// 
//     private static final Logger logger = LoggerFactory.getLogger(Transaction.class);
// 
//     private TransactionXid xid;
//     private TransactionStatus status;
//     private TransactionType transactionType;
//     private volatile int retriedCount = 0;
//     private Date createTime = new Date();
//     private Date lastUpdateTime = new Date();
//     private long version = 1;
// 
//     private List<Participant> participants = new ArrayList<>();
// 
//     private Map<String, Object> attachments = new ConcurrentHashMap<>();
// 
//     public Transaction() {
//     }
// 
//     public Transaction(TransactionContext transactionContext) {
//         this.xid = transactionContext.getXid();
//         this.status = TransactionStatus.TRYING;
//         this.transactionType = TransactionType.BRANCH;
//     }
// 
//     public Transaction(TransactionType transactionType) {
//         this.xid = new TransactionXid();
//         this.status = TransactionStatus.TRYING;
//         this.transactionType = transactionType;
//     }
// 
//     public void enlistParticipant(Participant participant) {
//         //logging......start
//         logger.debug("Enlist participant.");
//         Terminator terminator = participant.getTerminator();
//         if (terminator != null) {
//             logger.debug("Confirm class is:" + terminator.getConfirmInvocationContext().getTargetClass().getName());
//             logger.debug("Confirm method is:" + terminator.getConfirmInvocationContext().getMethodName());
//             logger.debug("Cancel class is:" + terminator.getCancelInvocationContext().getTargetClass().getName());
//             logger.debug("Cancel method is:" + terminator.getCancelInvocationContext().getMethodName());
//         }
//         //logging......end
//         participants.add(participant);
//     }
// 
//     public Xid getXid() {
//         return xid.clone();
//     }
// 
//     public TransactionStatus getStatus() {
//         return status;
//     }
// 
//     public List<Participant> getParticipants() {
//         return Collections.unmodifiableList(participants);
//     }
// 
//     public TransactionType getTransactionType() {
//         return transactionType;
//     }
// 
//     public void changeStatus(TransactionStatus status) {
//         this.status = status;
//     }
// 
//     public void commit() {
//         for (Participant participant : participants) {
//             participant.commit();
//         }
//     }
// 
//     public void rollback() {
//         for (Participant participant : participants) {
//             participant.rollback();
//         }
//     }
// 
//     public int getRetriedCount() {
//         return retriedCount;
//     }
// 
//     public void addRetriedCount() {
//         this.retriedCount++;
//     }
// 
//     public void resetRetriedCount(int retriedCount) {
//         this.retriedCount = retriedCount;
//     }
// 
//     public Map<String, Object> getAttachments() {
//         return attachments;
//     }
// 
//     public long getVersion() {
//         return version;
//     }
// 
//     public void updateVersion() {
//         this.version++;
//     }
// 
//     public void setVersion(long version) {
//         this.version = version;
//     }
// 
//     public Date getLastUpdateTime() {
//         return lastUpdateTime;
//     }
// 
//     public void setLastUpdateTime(Date date) {
//         this.lastUpdateTime = date;
//     }
// 
//     public Date getCreateTime() {
//         return createTime;
//     }
// 
//     public void updateTime() {
//         this.lastUpdateTime = new Date();
//     }
// 
// }
// 
// 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-api/src/main/java/org/pankai/tcctransaction/api/TransactionStatus.java
// public enum TransactionStatus {
// 
//     TRYING(1), CONFIRMING(2), CANCELLING(3);
// 
// 
//     private int id;
// 
//     TransactionStatus(int id) {
//         this.id = id;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public static TransactionStatus valueOf(int id) {
//         switch (id) {
//             case 1:
//                 return TRYING;
//             case 2:
//                 return CONFIRMING;
//             default:
//                 return CANCELLING;
//         }
// 
//     }
// }
// 
// 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-core/src/main/java/org/pankai/tcctransaction/recover/TransactionRecovery.java
import org.pankai.tcctransaction.Transaction;
import org.pankai.tcctransaction.TransactionRepository;
import org.pankai.tcctransaction.api.TransactionStatus;
import org.pankai.tcctransaction.support.TransactionConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

package org.pankai.tcctransaction.recover;



/**
 * 事务恢复器.当事务在指定的时间内未有状态变化时,会根据其上下文来决定提交,回滚或者是需要人工干预.
 * 可以在这里拓展需要人工干预时的通知.
 * Created by pktczwd on 2016/12/7.
 */
public class TransactionRecovery {

    private final Logger logger = LoggerFactory.getLogger(TransactionRecovery.class);

    private TransactionConfigurator transactionConfigurator;