From dfcc982e8fe46d83d8c5e705828073374c7e1dae Mon Sep 17 00:00:00 2001 From: Shubhra Srivastava Date: Tue, 11 Feb 2020 07:24:45 +0530 Subject: [PATCH] Review comments --- .../batch/SpringBatchRetryConfig.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/spring-batch/src/main/java/org/baeldung/batch/SpringBatchRetryConfig.java b/spring-batch/src/main/java/org/baeldung/batch/SpringBatchRetryConfig.java index 86ee82c7e4..4b30e47864 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/SpringBatchRetryConfig.java +++ b/spring-batch/src/main/java/org/baeldung/batch/SpringBatchRetryConfig.java @@ -32,6 +32,9 @@ import java.text.ParseException; @Configuration @EnableBatchProcessing public class SpringBatchRetryConfig { + + private static final String[] tokens = { "username", "userid", "transactiondate", "amount" }; + @Autowired private JobBuilderFactory jobBuilderFactory; @@ -45,14 +48,13 @@ public class SpringBatchRetryConfig { private Resource outputXml; public ItemReader itemReader(Resource inputData) throws UnexpectedInputException, ParseException { - FlatFileItemReader reader = new FlatFileItemReader<>(); DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); - String[] tokens = { "username", "userid", "transactiondate", "amount" }; tokenizer.setNames(tokens); - reader.setResource(inputData); DefaultLineMapper lineMapper = new DefaultLineMapper<>(); lineMapper.setLineTokenizer(tokenizer); lineMapper.setFieldSetMapper(new RecordFieldSetMapper()); + FlatFileItemReader reader = new FlatFileItemReader<>(); + reader.setResource(inputData); reader.setLinesToSkip(1); reader.setLineMapper(lineMapper); return reader; @@ -80,23 +82,25 @@ public class SpringBatchRetryConfig { } @Bean - public Step retryStep( - @Qualifier("retryItemProcessor") - ItemProcessor processor, ItemWriter writer) throws ParseException { - return stepBuilderFactory.get("retryStep").chunk(10).reader(itemReader(inputCsv)) - .processor(processor) - .writer(writer) - .faultTolerant() - .retryLimit(3) - .retry(ConnectTimeoutException.class) - .retry(DeadlockLoserDataAccessException.class) - .build(); + public Step retryStep(@Qualifier("retryItemProcessor") ItemProcessor processor + , ItemWriter writer) throws ParseException { + return stepBuilderFactory.get("retryStep") + .chunk(10) + .reader(itemReader(inputCsv)) + .processor(processor) + .writer(writer) + .faultTolerant() + .retryLimit(3) + .retry(ConnectTimeoutException.class) + .retry(DeadlockLoserDataAccessException.class) + .build(); } @Bean(name = "retryBatchJob") - public Job retryJob( - @Qualifier("retryStep") - Step retryStep) { - return jobBuilderFactory.get("retryBatchJob").start(retryStep).build(); + public Job retryJob(@Qualifier("retryStep") Step retryStep) { + return jobBuilderFactory + .get("retryBatchJob") + .start(retryStep) + .build(); } }