除了 read()、updated() 和 open() 方法之外,还有什么方法可以在执行上下文中添加条目。
就像在下面的代码中一样,我试图在 close 方法中添加条目。
public class MyFileReader extends FlatFileItemReader<AccountDetails>{
private long currentRowProcessedCount = 0;
@Autowired
private ExecutionContext executionContext;
@Override
public synchronized AccountDetails read() throws Exception, UnexpectedInputException, ParseException {
AccountDetails accDetailsObj = super.read();
currentRowProcessedCount++;
return accDetailsObj;
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
currentRowProcessedCount = executionContext.getLong(Constants.CONTEXT_COUNT_KEY.getStrValue(),0);
this.executionContext = executionContext;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), currentRowProcessedCount);
}
@Override
public void close() throws ItemStreamException {
System.out.println("close --------------"+currentRowProcessedCount);
System.out.println(executionContext.getLong(Constants.CONTEXT_COUNT_KEY.getStrValue()));
this.executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), currentRowProcessedCount);
}
}
在上面的示例中,我无法更新新条目。它只能以只读方式工作。我可以读取数据但不能写入。
class abc{
@Autowired
private ExecutionContext executionContext;
public AccountDetails mapFieldSet(FieldSet fieldSet) throws BindException {
executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), 47);
return accDetailsObj;
}
}
我还需要在其他类中更新 executionContext。有什么办法吗?