Here is my requirement : Create a batch job that 1. Fetches discount programs from Discount table for specific search critieria 2. For each discount program fetched in Step1, Get sales records for sales that fit the discount program dates Get additional details for sales from some other tables 3. Write the sales records into ReportTable 4. update discount table with status
3 options for implementations I could think of are : Option 1: (a) Create a DiscountReader that extends JdbcCursorItemReader that fetches discount programs based on dates and other criteria _ returns objects of type DiscountObj. (b) Created a SalesProcessor that implements ItemProcessor, with a SalesReader and SalesWriter. -> SalesReader should read records from salestable based on the current DiscountObj. -> SalesWriter to write the date fetched by SalesReader into database. (c) create DiscountWriter to update status into Discount table.
Option 2: (a) Create DiscountReader with a SalesReader inside ( ItemReader within ItemReader approach.)- which calls Salesreader for each DiscountObj being read. (b) Create SalesWriter to write the date fetched by SalesReader into database.
In any case, the parameters for the query executed by SalesReader is dynamic since it has to be extracted from the current DiscountObj. Are these the only 2 approaches or is there a better approach ?
If I inject the SalesReader into SalesProcessor/ DiscountReader, the open() method is being called before the preparedstatementsetter is set with the query parameters.
If I create instances of the SalesReader in SalesProcessor/ DiscountReader I get the exception that the Reader is not open.
Option 3: Create DiscountReader to read discounts. Create SalesProcessor which calls a DAO to get the sales records based on the discpuntObj Pass the data returned from the DAO to the writer.
Please help.