Reputation: 2076
I have a spring batch application that reads in CSV. What is the easiest way to get the number of records in the csv? I am a FlatFileItemReader<T>
and I tried placing a counter in the process()
method that we override for the Processor
, that I thought would increment for every row in the csv but I was getting very odd integer numbers. I can't do it in my Writer() implementation class because I do data validation in my processor class so if there are exceptions, the record size will be smaller and it won't reflect the real number of records originally.
I just need to know if someone loads in a file with 300,000 but only 250,000 get written to database, I want to know the real number of records in the original csv.
Upvotes: 2
Views: 2766
Reputation: 31710
I just need to know if someone loads in a file with 300,000 but only 250,000 get written to database, I want to know the real number of records in the original csv.
You can do that verification in a StepExecutionListener#afterStep(StepExecution stepExecution)
. This method gives you a reference to the step execution which allows you to get all counters like read.count
, write.count
, etc to implement your logic.
Upvotes: 4