Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Batch CompositeItemWriter,在遍历每个委托编写器结束时执行Batch以提高性能_Spring_Spring Batch_Spring Jdbc_Jdbctemplate - Fatal编程技术网

Spring Batch CompositeItemWriter,在遍历每个委托编写器结束时执行Batch以提高性能

Spring Batch CompositeItemWriter,在遍历每个委托编写器结束时执行Batch以提高性能,spring,spring-batch,spring-jdbc,jdbctemplate,Spring,Spring Batch,Spring Jdbc,Jdbctemplate,在SpringBatch中,我的CompositeItemWriter使用多个ItemWriter将记录插入到多个表中,但目前这些ItemWriter中的每一个都在批量插入,如下所示 public class Item{ public List<WarningObject> warnings public List<ErrorObject> errors public Long Id; public String data1; public Strin

在SpringBatch中,我的CompositeItemWriter使用多个ItemWriter将记录插入到多个表中,但目前这些ItemWriter中的每一个都在批量插入,如下所示

public class Item{
  public List<WarningObject> warnings
  public List<ErrorObject> errors
  public Long Id;
  public String data1;
  public String data2;
  public String data3;
  // getters and setters

}
公共类项目{
公共列表警告
公开列表错误
公共长Id;
公共字符串数据1;
公共字符串数据2;
公共字符串数据3;
//接球手和接球手
}
我的写入程序配置

<bean id="compositeItemWriter" class="org.springframework.batch.item.support.CompositeItemWriter">
<property name="delegates">
<list>
    <ref bean="warningItemWriter"/>
    <ref bean="errorItemWriter"/>
    <ref bean="CustomJdbcItemWriter"/>
</list>
</property>

公共类WarningItemWriter实现ItemWriter{
@自动连线
字符串sql;
@自动连线
jdbc模板;
@自动连线
ItemPreparedStatementSetter ItemPreparedStatementSetter;
@凌驾

public void write(final List只需将外部循环移动到匿名类的内部:

jdbcTemplate.execute(sql, new PreparedStatementCallBack<int []> {
    @Override
    public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
        for (Item item: items) {
            for (WarningObject warning: item.getWarnings) {
                itemPreparedStatementSetter.setValues(warning, ps);
                ps.addBatch();
             }
        }
        return ps.executeBatch();
    }
});
jdbcTemplate.execute(sql,new PreparedStatementCallBack{
@凌驾
public int[]doInPreparedStatement(PreparedStatement ps)抛出SQLException、DataAccessException{
用于(项目:项目){
用于(警告对象警告:item.getWarnings){
itemPreparedStatementSetter.setValues(警告,ps);
ps.addBatch();
}
}
返回ps.executeBatch();
}
});
jdbcTemplate.execute(sql, new PreparedStatementCallBack<int []> {
    @Override
    public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
        for (Item item: items) {
            for (WarningObject warning: item.getWarnings) {
                itemPreparedStatementSetter.setValues(warning, ps);
                ps.addBatch();
             }
        }
        return ps.executeBatch();
    }
});