[英]Spring Batch Reader Parameter Issue
Currently I need to implement the following steps with Spring batch: 当前,我需要使用Spring批处理实现以下步骤:
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
您的序列对应于以下内容
For the reader you could use a JdbcCursorItemReader
together with a RowMapper
to convert the result into an object. 对于阅读器,您可以将
JdbcCursorItemReader
与RowMapper
一起使用,以将结果转换为对象。 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
因此,您的步骤将是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.