0

I have 2 different file with different data. The file contains 10K record per day.

Ex:
Productname price date
T shirt,500,051221
Pant,1000,051221


Productname price date
T shirt,800,061221
Pant,1800,061221

I want to create final output file by checking price difference by todays and yesterdays file.

Ex: 
Productname price 
T shirt,300
Pant,800

By using spring batch I have to do this. I have tried with batch configuration by creating two different step. but its only able to read the data. but unable to do the processing. because here I need the data of both file for processing. but in my case its reading one step after another.

Could anyone help me on this with some sample code.

1 Answers1

0

I would suggest to save FlatFile data into the database for yesterday's and today's date (may be two separate tables or in a same table if you can identify difference two records easily). Read this stored data using JdbcCursorItemReader or PagingItemReader and perform calculation/logic/massaging of data at the processor level and create a new FlatFile or save into DB as per convenience. OOTB Spring Batch does not provide facility to read data and perform calculation.

Suggestion - Read data from both the FlatFile keep it in cache and read from the cache and do the further processing.

PAA
  • 1
  • 46
  • 174
  • 282
  • public class YesterFileWriter implements ItemWriter { private CacheManager cacheManager; public YesterFileWriter (CacheManager cacheManager) { this.cacheManager = cacheManager; } @Override public void write(List extends YesterdaysFile> items) throws Exception { cacheManager.getCache("YESTERDAYSFILE").put("listYesterdaysData", items); } } – Codinghubby Nov 02 '21 at 03:30
  • The above code snippet is to store data in cache, if I do this then same I will also have to do for todays file. Then Whether I need to configure another step for processing ? If yes then what needs to be done in reader, processor, writer to store final output in Database? Could you please explain this. – Codinghubby Nov 02 '21 at 03:46