com.swak.archiver.executor.impl.AbsArchiveExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swak-datarchiver-boot-starter Show documentation
Show all versions of swak-datarchiver-boot-starter Show documentation
swak component of data archiver spring boot starter
The newest version!
package com.swak.archiver.executor.impl;
import com.swak.archiver.common.IbsStringHelper;
import com.swak.archiver.conf.ArchiveConfig;
import com.swak.archiver.conf.ArchiveItem;
import com.swak.archiver.executor.ArchiveExecutor;
import com.swak.common.exception.ArchiveException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import java.util.List;
import java.util.Map;
/**
* AbsArchiveExecutor.java
*
* @author ColleyMa
* @version 19-5-10 上午11:14
*/
@Slf4j
public abstract class AbsArchiveExecutor implements ArchiveExecutor {
/**
* 获取归档目标表的最大maxId
*
* @param item
*/
protected void handlerNextMaxId(ArchiveItem item) {
ArchiveConfig config = item.getConfig();
try {
/** SELECT MAX(id) FROM xxx_archive; */
StringBuilder builderSql = new StringBuilder();
builderSql.append("SELECT MAX(id) FROM ").append(config.getDesTblName());
Long maxId = item.getExecutor().findMaxId(builderSql.toString());
log.warn("目标表nextMaxId获取 - 目标表: {} - nextMaxId(id) :{}", new Object[] { config.getDesTblName(), maxId });
// 设置最大的MaxId
item.setNextMaxId(maxId);
} catch (Exception e) {
log.error("目标表nextMaxId获取 - 目标表: {} - 异常信息: {}", config.getDesTblName(), e.getMessage());
ArchiveException.throwException(e);
}
}
public void commitArchiveLog(ArchiveItem item, int insertNum, int deleteNum, boolean isSucc) {
StringBuffer strBuff = new StringBuffer();
if (isSucc) {
strBuff.append("commit成功 ");
} else {
strBuff.append("执行失败回滚 ");
}
strBuff.append(" - 当前归档表 : ").append(item.getConfig().getSrcTblName());
strBuff.append(" - 目标表 : ").append(item.getConfig().getDesTblName());
strBuff.append(" - 最大max(id) : ").append(item.getMaxId());
strBuff.append(" - Limit数 : ").append(item.getConfig().getLimit());
strBuff.append(" - txn-size : ").append(item.getConfig().getTxnSize());
strBuff.append(" - 归档行数 : ").append(insertNum);
strBuff.append(" - 归档重复行数 : ").append(item.getRepeatNum().get());
strBuff.append(" - 删除行数: ").append(deleteNum);
strBuff.append(" - 重试总次数 : ").append(item.getRetries().get());
strBuff.append(" - 花费时间: ")
.append(IbsStringHelper.msTimeformat2String((System.currentTimeMillis() - item.getStartTime())));
log.warn(strBuff.toString());
}
public void commitDelLog(ArchiveItem item, int deleteNum, boolean isSucc) {
StringBuffer strBuff = new StringBuffer();
if (isSucc) {
strBuff.append("commit成功 ");
} else {
strBuff.append("执行失败回滚 ");
}
strBuff.append(" - 当前表 : ").append(item.getConfig().getSrcTblName());
strBuff.append(" - 最大max(id) : ").append(item.getMaxId());
strBuff.append(" - Limit数 : ").append(item.getConfig().getLimit());
strBuff.append(" - txn-size : ").append(item.getConfig().getTxnSize());
strBuff.append(" - 删除行数: ").append(deleteNum);
strBuff.append(" - 删除总行数: ").append(item.getDelNum().get());
strBuff.append(" - 剩余总行数: ").append(item.getConfig().getProgressSize()-item.getDelNum().get());
strBuff.append(" - 重试总次数 : ").append(item.getRetries().get());
strBuff.append(" - 花费时间: ")
.append(IbsStringHelper.msTimeformat2String((System.currentTimeMillis() - item.getStartTime())));
log.warn(strBuff.toString());
}
public class SwakTransactionCallback implements TransactionCallback {
private ArchiveItem item;
private List