Spring Integration: Inbound-channel-adapter update

2019-08-10 07:38发布

问题:

My goal is to read rows from table and put them on the channel as message and update the table. I am using RowMapper to convert the resultset into a list of Objects (List).

Here is my question: What should be the UPDATE Query parameter: STATUS_TABLE_ID IN (:payload[Status.id]), As the Payload would be List and to query the Status.Id is it the right syntax.

My Config:

<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>

My RowMapper Class:

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;
}

It would be great if someone could point me in the right direction.

回答1:

Assuming Status has a method getId(), you would simply use :id.

The update query uses projection over the collection of objects returned by the query...

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

This is described in the second Note here http://static.springsource.org/spring-integration/reference/html/jdbc.html#jdbc-inbound-channel-adapter

Collection Projection is described here http://static.springsource.org/spring-framework/docs/3.2.1.RELEASE/spring-framework-reference/html/expressions.html#expressions-collection-projection