I'm using java configuration (spring-boot) for spring batch. I have a list of Employee Ids and for each Id, I need to run a query (like below) and then process the data.
select * from history where employee_id = ?
I understand we can use reader.setPreparedStatementSetter to dynamically set the parameter in the above SQL. However, I'm not sure how I can repeat the batch process for each of the employee id in the list. Even if I mark the reader() as @StepScope, the reader is called only once. (i.e.), the batch runs only once. Any help is appreciated.
List employeeIds = new ArrayList();
employeeIds.add(1);
employeeIds.add(2);
@Bean
@StepScope
public ItemReader<History> reader() {
JdbcCursorItemReader<History> databaseReader = new JdbcCursorItemReader<>();
databaseReader.setSql("select * from history where employee_id = ?");
databaseReader.setPreparedStatementSetter(..);
....
return databaseReader;
}
@Bean
public Step step(StepBuilder stepBuilder){
return stepBuilderFactory.get("sample").
.reader(reader())
.processor(processor())
.writer(writer())
.build();
}