int-jdbc:inbound-channel-adapter更新查询的系统变量

时间:2018-08-07 17:39:47

标签: spring spring-integration spring-jdbc

我正在使用int-jdbc:inbound-channel-adapter。 我的更新语句遇到问题。我需要传递单个值,因为我已经在RowMapper中对该值进行了硬编码,这就是为什么我收到5个值代替1.(max-rows-per-poll = 5)

我的要求:-我需要将系统变量传递给node_id列,并从选择查询中选择5个ID到条件

<int-jdbc:inbound-channel-adapter id="itemsInboundJdbcChannelAdapter"
        auto-startup="true" data-source="dataSource" channel="ItemsInboundJdbcChannel"
        query="SELECT QXXXX_ID,BXXXX_ID,TXXXX_ID,RXXXX_ID,EXXXXID,NODE_ID FROM XXXX_QXXXX WHERE XXXX_STATUS = :identier ORDER BY QXXXX_ID asc FOR UPDATE SKIP LOCKED"
        update="UPDATE XXXX_QXXXX SET XXXX_STATUS ='IT_PROCESSED',NODE_ID=(:NODE_ID),UPDATE_BY='BISWO',UPDATED_ON=SYSDATE WHERE QXXXX_ID IN (:QXXXX_ID)"
        row-mapper="xxDataRowMapper" max-rows-per-poll="${item.transfer.jdbc.max.rows}"
        select-sql-parameter-source="myItemsSelectSqlParameterSource"
        update-sql-parameter-source-factory="myUpdateParameterSource">
        <int:poller id="jdbcPoller" fixed-delay="${item.transfer.poller.jdbc.fixed.delay}" task-executor="notificationExecutor"  error-channel="chainToFailedOut">
            <int:transactional transaction-manager="transactionManager" />
        </int:poller>
</int-jdbc:inbound-channel-adapter>

<int:service-activator input-channel="ItemsInboundJdbcChannel"
        ref="getMyService" >
        <int:poller fixed-delay="${item.transfer.poller.jdbc.fixed.delay}" />
    </int:service-activator>

 

<bean id="myUpdateParameterSource"
        class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
        <property name="parameterExpressions">
            <map>
                <entry key="NODE_ID" value=" #this['nodeId']"/>
                <entry key="QXXXX_ID" value="#this['qxxxxId']" />
            </map>
        </property>
</bean>

xxxDataRowMapper.java

@Override
public XXXDataModel mapRow(ResultSet rs, int rowNum) throws SQLException {
    XXDataModel object=null;
    if(rs!=null){
     long queueId=rs.getLong("QXXXX_ID");
     long batchId=rs.getLong("BXXXX_ID");
     long tradeRunId=rs.getLong("TXXXX_ID");
     long riskRunId=rs.getLong("RXXXX_RUN_ID");
    long eventId=rs.getLong("EXXXXID");
      object=new XXDataModel(queueId,batchId,tradeRunId,riskRunId,eventId,this.nodeId);
    }
    return object;
}

1 个答案:

答案 0 :(得分:1)

我认为您可以简单地按照properties placeholder的方式执行类似的操作:

update="UPDATE XXXX_QXXXX SET XXXX_STATUS ='IT_PROCESSED',NODE_ID='${node_id.from-system.properties}', UPDATE_BY='BISWO',UPDATED_ON=SYSDATE WHERE QXXXX_ID IN (:QXXXX_ID)"

Spring将了解您的PP模式,并根据Environment对其进行解析,最终值将出现在要使用的目标SQL语句中。