1

I want to read multiple tables to fetch few fields from each of these table & write it to a xml. I have created a custom ItemReader and have multiple queries. I have two issues

1) My Reader goes into an infinte loop as I am not sure when & how to return null

2) What is the best way to consolidate data from multiple tables & send it to ItemWriter ?

public class SolrTransformProductReader implements ItemReader <ProductWithPrograms> {


    @Autowired
    private JdbcTemplate jdbcTemplate;

    private String sql1 = "Select PRODUCT_CODE from product";
    private String sql2 = "Select PRODUCT_CODE, CONTRIBUTOR_ID  from product_Contributor";

    @Override
    public ProductWithPrograms read() throws Exception {

        SqlRowSet  productRows = jdbcTemplate.queryForRowSet(sql1);

        while(productRows.next()) {

            System.out.println("Product Code " + productRows.getString("PRODUCT_CODE"));
            ProductWithPrograms pp = new ProductWithPrograms();
            pp.setProduct_Code(productRows.getString("PRODUCT_CODE"));
            return pp;
        }

        return null;

    }

}

And my xml is as below

<job id="SEG_SolrTransformation" xmlns="http://www.springframework.org/schema/batch">
        <batch:step id="solrProductTransformation">
            <tasklet>
                <chunk reader="solrTransformProductReader" writer="solrTransformProductWriter" commit-interval="999" />
            </tasklet>
        </batch:step>
    </job>
user3553141
  • 109
  • 3
  • 9
  • I think you can accomodate http://stackoverflow.com/questions/21304364/spring-batch-job-read-from-multiple-database to match your needs – Luca Basso Ricci Aug 19 '15 at 19:11

1 Answers1

0

better try to use JdbcPgingItemReader for reading the data ,which is provided by spring batch. you can create start multile instances of jobs for each table and convert them into xml.

you can specify select,from,where clauses as parameters for the job

ravinder reddy
  • 309
  • 1
  • 4
  • 17
  • Could you please provide sample snippet or git link or url etc to support your answer? – PAA Apr 02 '16 at 07:02