【问题标题】:Spring Integration: Inbound-channel-adapter update query parameter exception when using RowMapperSpring Integration:使用 RowMapper 时的 Inbound-channel-adapter 更新查询参数异常
【发布时间】:2014-04-22 01:23:56
【问题描述】:

我的目标是从表中读取行并将它们作为消息放在通道上并更新表。 我正在使用 RowMapper 将结果集转换为对象列表(列表)。

这是我的问题: UPDATE Query 参数应该是什么:STATUS_TABLE_ID IN (:payload[Status.id]),因为 Payload 将是 List 和 to查询 Status.Id 是否是正确的语法。

我的配置:

<si:channel id="output">
    <si:queue capacity="50" />
<si:interceptors>
     <si:wire-tap channel="logger"/>
 </si:interceptors>
</si:channel>
<si-jdbc:inbound-channel-adapter channel="input" data-source="myDataSource" auto-startup="true" query="SELECT * FROM STATUS_TABLE WHERE MESSAGE_STATUS ='WAITING'"
                                 update="UPDATE STATUS_TABLE SET MESSAGE_STATUS='IN_PROGRESS' WHERE STATUS_TABLE_ID IN (:payload[Status.id])"  max-rows-per-poll="20"  row-mapper="rowMapper" update-per-row="true">
    <si:poller fixed-rate="60000">
        <si:transactional/>
    </si:poller>
</si-jdbc:inbound-channel-adapter>

<bean id="rowMapper" class="com.test.StatusMapper"></bean>

我的 RowMapper 类:

public class StatusMapper implements RowMapper<Status>{

@Override
public Status mapRow(ResultSet rs, int rowNum)throws SQLException {

    Status status = new Status();       
    status.setMessageContent(rs.getString("MESSAGE_CONTENT"));      
    status.setId(rs.getLong("STATUS_ID"));      
    return status;
}

如果有人能指出我正确的方向,那就太好了。

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    假设Status 有一个方法getId(),您只需使用:id

    更新查询对查询返回的对象集合使用投影...

    expression = "#root.![" + expression + "]";

    这在第二个Note这里有描述http://static.springsource.org/spring-integration/reference/html/jdbc.html#jdbc-inbound-channel-adapter

    这里描述了集合投影http://static.springsource.org/spring-framework/docs/3.2.1.RELEASE/spring-framework-reference/html/expressions.html#expressions-collection-projection

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多