我正在开发一个读取一些文件并将其保存到数据库的 Spring Batch 应用程序。我正在使用跳过策略处理错误情况。如何访问阅读器中读取的文件名?
public FileProcessSkipper(int skipCount) {
this.configuredSkipCount = skipCount;
}
@Override
public boolean shouldSkip(Throwable exception, int skipCount) throws SkipLimitExceededException {
if (exception instanceof FileNotFoundException) {
return false;
} else if (exception instanceof FlatFileParseException && skipCount < configuredSkipCount) {
FlatFileParseException ffpe = (FlatFileParseException) exception;
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("An error occured while processing the " + ffpe.getLineNumber()
+ " line of the file. Below was the faulty " + "input.\n");
errorMessage.append(ffpe.getInput() + "\n");
log.error("{}", errorMessage.toString());
return true;
} else if (exception instanceof DateTimeParseException && skipCount < configuredSkipCount) {
DateTimeParseException ffpe = (DateTimeParseException) exception;
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("An error occured while processing the Record. Below was the faulty input.\n");
errorMessage.append(ffpe.getParsedString() + "\n");
log.error("{}", errorMessage.toString());
return true;
} else if (exception instanceof DataIntegrityViolationException && skipCount < configuredSkipCount) {
DataIntegrityViolationException dive = (DataIntegrityViolationException) exception;
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("An error occured while loading Record into the database Below was the faulty " + "input.\n");
errorMessage.append(dive.getMessage() + "\n");
log.error("{}", errorMessage.toString());
return true;
} else {
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("Error Count exceeded threshold configures skip count "+configuredSkipCount+" and the Job is being failed.\n");
return false;
}
}