我有以下 ItemProcessor,我需要知道该项目是否是阅读器发送的最后一个项目。这可能吗?
流程是:
ItemReader
- 从数据库中读取行(预计数百万行)ItemProcessor
- 对每一行执行一些验证,发送到 webservice 并使用 webservice 响应执行更多验证。ItemWriter
- 从验证中写入数据库错误,并更改线路状态。
另一种可能的解决方案是 ItemReader 发送Line
带有大小的列表NUMBER_OF_LINES_TO_CALL_WEBSERVICE
,但我找不到有关如何修改JpaPagingItemReader
.
@Override
public List<Line> process(Line line) {
lineList.add(line);
if (lineList.size() == NUMBER_OF_LINES_TO_CALL_WEBSERVICE) {
callWs(lineList);
return lineList; // goes to ItemWriter to write the response from ws in database
}
if( /* TODO if last line */) {
callWs(lineList);
return lineList;
}
return null;
}
private void callWs(List<Line> lineList){
...
//Get response from webservice and add info to lines
}
@Override
public void afterChunk(ChunkContext chunkContext) {
if (lineList.size() == NUMBER_OF_LINES_TO_CALL_WEBSERVICE) {
lineList.clear();
}
}
读者是JpaPagingItemReader
:
@Bean
@StepScope
public JpaPagingItemReader<Line> itemReader(@Qualifier("EntityManagerFactory") EntityManagerFactory entityManagerFactory) {
String queryStr = "select l from Line l" ;
return new JpaPagingItemReaderBuilder<Linha>()
.name("lineReader")
.entityManagerFactory(entityManagerFactory)
.queryString(queryStr)
.pageSize(PAGE_SIZE)
.build();
}