1
I am trying to build a Rest api to recover data from a table using spring batch.
Below my service Rest:
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
public List<Deposit> requestJob1() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, NoSuchJobException, JobParametersNotFoundException, UnexpectedJobExecutionException {
jobLauncher.run(jdbcCursorReaderJob, new JobParametersBuilder().addLong("uniqueness", System.nanoTime()).toJobParameters());
return ?
Down with my Reader:
@Bean
public JdbcCursorItemReader<Deposit> jdbcCursorReader(
@Qualifier("datasource") DataSource dataSource) {
return new JdbcCursorItemReaderBuilder<Deposit>()
.name("jdbcCursorReader")
.dataSource(dataSource)
.sql("select * from depositos")
.rowMapper(new BeanPropertyRowMapper<Deposit>(Deposit.class))
.build();
}
Down with my Writer:
public class JdbcCursorWriterConfig implements ItemWriter<Deposit> {
List<Deposit> output = TransactionAwareProxyFactory.createTransactionalList();
public void write(List<? extends Deposit> items) throws Exception {
output.addAll(items);
}
public List<Deposit> getOutput() {
return output;
}
}
My doubts are:
1 - I think my Writer is wrong. How exactly should I write my Writer? 2 - How should I manipulate my Writer return in the Rest requestJob1 method?