简体   繁体   English

Spring Batch Reader参数问题

[英]Spring Batch Reader Parameter Issue

Currently I need to implement the following steps with Spring batch: 当前,我需要使用Spring批处理实现以下步骤:

  1. Read table data from data source A; 从数据源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; 根据在步骤1中从数据源A获得的列值,从数据源B读取表数据作为搜索条件;
  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? 从技术上讲,我对步骤1和步骤3没问题,但是任何人都可以建议如何解决步骤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? 我知道在步骤1之后,我可以获得一个rowMapper类,该类将每行数据映射到我的域对象,在这种情况下,如何将列值(域对象属性)作为参数传递给步骤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 ItemReader
  2. ItemProcessor ItemProcessor
  3. ItemWriter ItemWriter

For the reader you could use a JdbcCursorItemReader together with a RowMapper to convert the result into an object. 对于阅读器,您可以将JdbcCursorItemReaderRowMapper一起使用,以将结果转换为对象。 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. ItemProcessor您可以将JdbcTemplate与查询一起使用,并使用传入的对象将参数添加到查询中,并与另一个RowMapper一起将结果转换为对象。 This object is passed to the ItemWriter which stores the object you could use a JdbcBatchItemWriter for that. 该对象将传递到ItemWriter ,该对象存储可以JdbcBatchItemWriter使用JdbcBatchItemWriter的对象。

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). 根据您对步骤2/3的需求,您可以尝试创建一个自定义编写器,该编写器可以在单个查询中进行处理(读取/更新)(这可能比读取,构造对象和再次写入更快。

Why don't you create Staging table in Datasource B( I assume its different database). 为什么不在数据源B中创建登台表(我假设它是不同的数据库)。 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. 步骤1:从数据源A读取数据并写入数据源B的登台表。
  2. Step2: Read the data from Datasouce B and write to file/some other place. 步骤2:从Datasouce B读取数据并写入文件/其他地方。 (Tweek your select statement fetch in step2 to meet your conditions. (Tweek,您的select语句在步骤2中提取,以满足您的条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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