Spring Integration JDBC数组更新查询Spel表达式

时间:2018-08-17 14:05:18

标签: spring-integration spring-jdbc spring-el

我正在尝试按照以下工作流程为我的JdbcPollingChannelAdapter创建一个“更新查询”:

  1. 从数据库中选择500条A型记录
  2. 使用最近读取的记录(位置500处的记录)的值更新另一个表中的1行

但是由于尝试使用spring-el来查找值,我无法对其进行分类。

通过调试,我达到了JdbcPollingChannelAdapter executeUpdateQuery方法,

void executeUpdateQuery(Object obj) {
        SqlParameterSource updateParameterSource = this.sqlParameterSourceFactory.createParameterSource(obj);
        this.jdbcOperations.update(this.updateSql, updateParameterSource);
    }

其中Object obj是A类型的500条记录的ArrayList

这是我最好的搭配:

UPDATE LAST_EVENT_READ SET SEQUENCE=:#root[499].sequence, EVENT_DATE=:#[499].eventDate

有人可以帮助我吗?

P.S。类型A具有sequence和eventDate属性

1 个答案:

答案 0 :(得分:1)

我建议您使用自定义SqlParameterSourceFactory并且已经不依赖SpEL:

public class CustomSqlParameterSourceFactory implements SqlParameterSourceFactory {

    @Override
    public SqlParameterSource createParameterSource(Object input) {
        List<?> objects = (List<?>) input;
        return new BeanPropertySqlParameterSource(objects.get(objects.size() - 1));
    }

}

将其注入JdbcPollingChannelAdapter.setUpdateSqlParameterSourceFactory()中,并已在UPDATE语句中使用简单的属性:

UPDATE LAST_EVENT_READ SET SEQUENCE=:sequence, EVENT_DATE=:eventDate