I'm running a straight forward batch job to read a record from DB2 DB, I'm not getting any result in the output or an error even.
Any glance of where I'm missing anything?
Here is the code of the batch.
@Configuration
@EnableBatchProcessing
@AllArgsConstructor
public class ETLConfig {
private JobBuilderFactory jobBuilderFactory;
private StepBuilderFactory stepBuilderFactory;
private EntityManagerFactory emf;
@Bean
public Step sampleStep(){
return stepBuilderFactory.get("sampleStep")
.<String, String>chunk(5)
.reader(itemReader())
.writer(i -> i.stream().forEach(j -> System.out.println(j)))
.build();
}
@Bean
public Job sampleJob(){
return jobBuilderFactory.get("sampleJob")
.incrementer(new RunIdIncrementer())
.start(sampleStep())
.build();
}
@Bean
public JpaPagingItemReader itemReader(/*@Value("${query}") String query*/){
return new JpaPagingItemReaderBuilder<>()
.name("db2Reader")
.entityManagerFactory(emf)
.queryString("select * FROM EXPORT.FCR_HDR F WHERE F.FCR_REF = 'R2G0128330'")
.pageSize(3)
.build();
}
}
If I run the same query on the DB I'm getting the output of this Reference.
@Component
@AllArgsConstructor
public class NoPersistenceBatchConfigurer extends DefaultBatchConfigurer {
@Bean
public DataSource batchDataSource() throws ClassNotFoundException {
return DataSourceBuilder.create()
.driverClassName("org.h2.Driver")
.url("jdbc:h2:mem:testdb")
.username("sa")
.password("")
.build();
}
@Override
public void setDataSource(DataSource batchDataSource) {
try {
super.setDataSource(batchDataSource());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}