我正在使用JdbcPagingItemReader,如下所示
Setup.hs
截至目前,我按照以下方式开展工作(因为我对Spring批次很新)
@Bean
public ItemReader<RemittanceVO> reader() {
JdbcPagingItemReader<RemittanceVO> reader = new JdbcPagingItemReader<RemittanceVO>();
reader.setDataSource(dataSource);
reader.setRowMapper(new RemittanceRowMapper());
reader.setQueryProvider(queryProvider);
reader.setPageSize(100);
return reader;
}
@Bean
public PagingQueryProvider queryProvider() throws Exception{
SqlPagingQueryProviderFactoryBean queryProviderBean= new SqlPagingQueryProviderFactoryBean();
queryProviderBean.setDataSource(dataSource);
queryProviderBean.setSelectClause(Constants.REMITTANCES_SELECT_CLAUSE);
queryProviderBean.setFromClause(Constants.REMITTANCES_FROM_CLAUSE);
queryProviderBean.setWhereClause(Constants.REMITTANCES_WHERE_CLAUSE);
queryProviderBean.setSortKey(Constants.REMITTANCES_SORT_KEY);
PagingQueryProvider queryProvider = queryProviderBean.getObject();
return queryProvider;
}
我正在以SpringBoot应用程序运行此应用程序。它成功获取前100个记录并移交给处理器,然后下一个查询失败。查询失败,因为尚未在其中放置排序键值。这是查询中的JobLauncher jobLauncher = (JobLauncher) ctx.getBean("jobLauncher");
Job job = (Job) ctx.getBean("runRCMatcher");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
}catch (Exception e) {
e.printStackTrace();
}
我哪里错了?
我的数据库是DB2所以我想应该使用 - AND ((REMIT_ID > ?)) ORDER BY REMIT_ID ASC FETCH FIRST 100 ROWS ONLY;
步骤&amp;作业定义为,
Db2PagingQueryProvider
指定的排序键是表列名称 - @Bean
public Step step1(StepBuilderFactory stepBuilderFactory,
ItemReader<RemittanceVO> reader, ItemWriter<RemittanceClaimVO> writer,
ItemProcessor<RemittanceVO, RemittanceClaimVO> processor) {
return stepBuilderFactory.get("step1")
.<RemittanceVO, RemittanceClaimVO> chunk(100).reader(reader)
.processor(processor).writer(writer).build();
}
@Bean
public Job runRCMatcher(JobBuilderFactory jobs, Step s1) {
return jobs.get("RCMatcher")
.incrementer(new RunIdIncrementer())
.flow(s1)
.end()
.build();
}
,它是表的主键,类型为Constants.REMITTANCES_SORT_KEY