简体   繁体   中英

Spring Batch Reader Parameter Issue

Currently I need to implement the following steps with Spring batch:

  1. Read table data from data source A;
  2. Read table data from data source B based on the column values I get from data source A at step 1 as search criteria;
  3. Write what I get at step 2 to some other place

Technically I have no problem dealing with step 1 and step 3, but anyone could advise how to tackle step 2? I understand that after step 1 I can get a rowMapper class that maps each row of data to my domain object, in this case how to pass the column values (domain object attributes) as the parameters to step 2?

春季批处理

As I tried to explain in the comments (and in the link to the documentation ). Use a chunk oriented step. Your sequence corresponds to the following

  1. ItemReader
  2. ItemProcessor
  3. ItemWriter

For the reader you could use a JdbcCursorItemReader together with a RowMapper to convert the result into an object. In the ItemProcessor you use a JdbcTemplate with a query and use the incoming object to add the parameters to the query, together with another RowMapper this will convert the result into an object. This object is passed to the ItemWriter which stores the object you could use a JdbcBatchItemWriter for that.

Depending on your needs for step 2/3 you could try to create a custom writer which does the processing (reading/updating) in a single query (this could be faster then reading, constructing objects and writing again).

Why don't you create Staging table in Datasource B( I assume its different database). And tweek your query. Hence your step would be

  1. Step1: Read the data from DataSource A and write to staging table of Datasource B.
  2. Step2: Read the data from Datasouce B and write to file/some other place. (Tweek your select statement fetch in step2 to meet your conditions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM