I need to capture the runtime exception in reader and skip them, so I use skipPolicy to do that as below. Also there is a requirement to record which data causes the runtime exception. I have some conversion logic in reader, but ItemReadListener does not have the access to item info. I am not sure where/how to access such data info.
Should I move the the conversion logic from reader to processor, then implement ItemProcessListener to record the error item? In this case, should the step1 method be udpated below? Thanks in advance!
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.reader(reader1())
.faultTolerant().skipPolicy(runtimeExceptionSkipper())
.processor(processor1())
.writer(writer1())
.build();
}
@Bean(destroyMethod="")
public JdbcCursorItemReader<Job> reader1() {
return new JdbcCursorItemReaderBuilder<Job>()
.dataSource(dataSourceConfig.dataSource())
.name("reader1")
.sql(Constants.QUERY_JOB_SQL)
.rowMapper(new JobRowMapper())
.build();
}
public class JobRowMapper implements RowMapper<Job> {
public Job mapRow(ResultSet rs, int rowNum) throws SQLException {
Job jobSchedule = new Job();
String timeZone = rs.getString(Constants.COLUMN1);
LocalDateTime localStart =
rs.getTimestamp(Constants.COLUMN2).toLocalDateTime();
ZonedDateTime utcStart = ZonedDateTime.of(localStart,
ZoneId.of("GMT"));
ZonedDateTime zonedStart =
utcStart.withZoneSameInstant(ZoneId.of(timeZone));
job.setEffectDate(zonedStart.toLocalDate());
return job;
}
}
@Bean
public Step updatedStep1() {
return stepBuilderFactory.get("updatedStep1")
.reader(reader1())
.processor(processor1())
.faultTolerant().skipPolicy(runtimeExceptionSkipper())
.listener(itemProcessListener())
.writer(writer1())
.build();
}