docs: 更新批量更新相关类的JavaDoc文档
- 优化 BatchUpdateErrorInfo、BatchUpdateResult 类和成员的注释 - 为 BatchUpdateStatus 枚举添加详细的类注释和枚举值注释
This commit is contained in:
@@ -16,31 +16,66 @@
|
||||
package xyz.zhouxy.jdbc;
|
||||
|
||||
/**
|
||||
* 批量更新错误信息
|
||||
* 记录批量更新操作中某个批次的执行错误信息。
|
||||
*
|
||||
* <p>当批量更新过程中某个批次执行失败时,该类用于封装出错批次的索引、
|
||||
* 异常原因及其错误类型,便于调用方进行针对性的错误处理。
|
||||
*
|
||||
* @author ZhouXY
|
||||
* @see BatchUpdateResult
|
||||
*/
|
||||
public class BatchUpdateErrorInfo {
|
||||
|
||||
/**
|
||||
* 批次索引
|
||||
*/
|
||||
private final int batchIndex;
|
||||
/**
|
||||
* 错误原因
|
||||
*/
|
||||
private final Throwable cause;
|
||||
/**
|
||||
* 错误类型
|
||||
*/
|
||||
private final Class<? extends Throwable> errorType;
|
||||
|
||||
/**
|
||||
* 构造一个批量更新错误信息实例。
|
||||
*
|
||||
* @param batchIndex 出错的批次索引
|
||||
* @param cause 导致该批次执行失败的异常
|
||||
*/
|
||||
public BatchUpdateErrorInfo(int batchIndex, Throwable cause) {
|
||||
this.batchIndex = batchIndex;
|
||||
this.cause = cause;
|
||||
this.errorType = cause.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取批次索引
|
||||
*
|
||||
* @return 批次索引
|
||||
*/
|
||||
public int getBatchIndex() {
|
||||
return batchIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误原因
|
||||
*
|
||||
* @return 错误原因
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误类型
|
||||
*
|
||||
* @return 错误类型
|
||||
*/
|
||||
public Class<? extends Throwable> getErrorType() {
|
||||
return errorType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,20 +22,57 @@ import java.util.Map;
|
||||
/**
|
||||
* 批量更新结果
|
||||
*
|
||||
* <p>
|
||||
* 封装 {@code batchUpdate} 操作的执行结果,包含:
|
||||
* <ul>
|
||||
* <li>整体执行状态 {@link BatchUpdateStatus}</li>
|
||||
* <li>批次统计信息(总数据量、批次数、成功/失败/剩余批次数)</li>
|
||||
* <li>各批次的更新结果及各错误批次的异常信息</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author ZhouXY
|
||||
*
|
||||
* @see BatchUpdateStatus
|
||||
* @see BatchUpdateErrorInfo
|
||||
* @see JdbcOperations#batchUpdate(String, java.util.Collection, int)
|
||||
* @see JdbcOperations#batchUpdate(String, java.util.Collection, int, boolean)
|
||||
*/
|
||||
public class BatchUpdateResult {
|
||||
/**
|
||||
* 总数据量
|
||||
*/
|
||||
private final int total;
|
||||
/**
|
||||
* 批次数量
|
||||
*/
|
||||
private final int batchCount;
|
||||
/**
|
||||
* 批次大小
|
||||
*/
|
||||
private final int batchSize;
|
||||
|
||||
/**
|
||||
* 本次分批更新的状态
|
||||
*/
|
||||
private BatchUpdateStatus status = BatchUpdateStatus.SUCCESS;
|
||||
|
||||
/**
|
||||
* 所有批次的更新结果
|
||||
*/
|
||||
private Map<Integer, int[]> allUpdateCounts;
|
||||
/**
|
||||
* 所有出错的批次的错误信息
|
||||
*/
|
||||
private Map<Integer, BatchUpdateErrorInfo> allErrorsInfo;
|
||||
|
||||
/**
|
||||
* 成功批次数量
|
||||
*/
|
||||
private int successBatchCount;
|
||||
|
||||
/**
|
||||
* 完成批次数量
|
||||
*/
|
||||
private int completeBatchCount;
|
||||
|
||||
BatchUpdateResult(int total, int batchCount, int batchSize) {
|
||||
@@ -76,7 +113,7 @@ public class BatchUpdateResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取批次更新结果
|
||||
* 获取指定批次更新结果
|
||||
*
|
||||
* @param batchIndex 批次号
|
||||
* @return 批次更新结果
|
||||
@@ -87,7 +124,7 @@ public class BatchUpdateResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误批次号
|
||||
* 获取所有出错的批次号
|
||||
*
|
||||
* @return 错误批次号
|
||||
*/
|
||||
@@ -96,7 +133,7 @@ public class BatchUpdateResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误批次信息
|
||||
* 获取指定批次的错误信息
|
||||
*
|
||||
* @param batchIndex 批次号
|
||||
* @return 批次错误信息
|
||||
@@ -106,7 +143,7 @@ public class BatchUpdateResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有错误批次信息
|
||||
* 获取所有出错的批次的错误信息
|
||||
*
|
||||
* @return 批次错误信息
|
||||
*/
|
||||
@@ -142,9 +179,9 @@ public class BatchUpdateResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取批次更新状态
|
||||
* 获取批量更新状态
|
||||
*
|
||||
* @return 批次更新状态
|
||||
* @return 批量更新状态
|
||||
*/
|
||||
public BatchUpdateStatus getStatus() {
|
||||
return status;
|
||||
@@ -180,12 +217,16 @@ public class BatchUpdateResult {
|
||||
/**
|
||||
* 获取剩余批次数量
|
||||
*
|
||||
* <p>
|
||||
* 一般是中断后未执行的批次数量
|
||||
*
|
||||
* @return 剩余批次数量
|
||||
*/
|
||||
public int getRemainingBatchCount() {
|
||||
return batchCount - successBatchCount - getErrorBatchCount();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BatchUpdateResult ["
|
||||
|
||||
@@ -20,7 +20,12 @@ import xyz.zhouxy.plusone.commons.base.IWithIntCode;
|
||||
/**
|
||||
* 批量更新状态
|
||||
*
|
||||
* <p>
|
||||
* 用于表示批量更新操作的整体执行状态
|
||||
*
|
||||
* @author ZhouXY
|
||||
* @see BatchUpdateResult
|
||||
* @see BatchUpdateResult#getStatus()
|
||||
*/
|
||||
public enum BatchUpdateStatus implements IWithIntCode {
|
||||
|
||||
@@ -30,12 +35,20 @@ public enum BatchUpdateStatus implements IWithIntCode {
|
||||
SUCCESS(0, "成功"),
|
||||
|
||||
/**
|
||||
* 部分成功
|
||||
* 执行完成,部分批次失败
|
||||
*
|
||||
* <p>
|
||||
* 通常出现在 batchUpdate 的静默模式下:遇到执行失败的批次时不中断,继续执行后续批次,最终状态为此值。
|
||||
*
|
||||
* @see BatchUpdateResult#getErrorBatchIndexes()
|
||||
*/
|
||||
COMPLETED_WITH_ERRORS(-1, "部分成功"),
|
||||
COMPLETED_WITH_ERRORS(-1, "执行完成,部分批次失败"),
|
||||
|
||||
/**
|
||||
* 中断
|
||||
*
|
||||
* <p>
|
||||
* 通常出现在 batchUpdate 的非静默模式下:遇到执行失败的批次时立即中断,不再执行后续批次。
|
||||
*/
|
||||
INTERRUPTED(-2, "中断"),
|
||||
;
|
||||
@@ -48,18 +61,26 @@ public enum BatchUpdateStatus implements IWithIntCode {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
* 获取状态的可读描述
|
||||
*
|
||||
* @return 描述信息
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BatchUpdateStatus ["
|
||||
|
||||
Reference in New Issue
Block a user