Spring Integration的JDBC入站通道适配器是否轮询表中新增的记录?

huangapple go评论44阅读模式
英文:

Does Spring Integration's JDBC inbound channel adapter poll new records added the table?

问题

我已经编写了如下的jdbc入站通道适配器。我正在使用更新查询。但是它没有工作。查询检索了两行,但更新语句没有将这两行的“accType”设置为'P'。 请建议。

<int-jdbc:inbound-channel-adapter id="jdbcInbound"
              channel="channel"
              data-source="dataSource"
              query="SELECT id, acct_nam FROM Accounts where accType ='N'"       
              update="update Accounts set accType='P' where ID in (:id)"        
              row-mapper="AccountRowMapper"
              max-rows-per-poll="100">
    <int:poller fixed-rate="1000"/>
</int-jdbc:inbound-channel-adapter>
英文:

I have written jdbcinboud channel adapter as below. I am using update query. however it is not working. The query retrieves two rows, but update statement does not set the accType of these two rows to 'P'.
Please advise

&lt;int-jdbc:inbound-channel-adapter id=&quot;jdbcInbound&quot;
          channel=&quot;channel&quot;
          data-source=&quot;dataSource&quot;
          query=&quot;SELECT id, acct_nam FROM Accounts where accType =&#39;N&#39;&quot;       
          update=&quot;update Accounts set accType=&#39;P&#39; where ID in (:id)        
          row-mapper=&quot;AccountRowMapper&quot;
          max-rows-per-poll=&quot;100&quot;&gt;
    &lt;int:poller fixed-rate=&quot;1000&quot;/&gt;
&lt;/int-jdbc:inbound-channel-adapter&gt;

答案1

得分: 0

它在每次轮询周期都调用 query=&quot;SELECT * FROM Accounts&quot;,并提取 100 行,可能在您的情况下这些只是第一个 100 行,因为没有其他筛选条件。

一般来说,没有任何 WHERE 子句的常规 SELECT 是不好的做法。

请注意,有一个 update 属性可以用于针对刚刚提取的行执行操作。您的 SELECT 必须使用 WHERE 进行调整,以仅选择以前未更新的行。

在文档中查看更多信息:https://docs.spring.io/spring-integration/reference/html/jdbc.html#jdbc-inbound-channel-adapter

英文:

It does call that query=&quot;SELECT * FROM Accounts&quot; on every polling cycle and pulls 100 rows and probably in your case those are only first 100 since there is no other criteria to filter out.

In general it is bad practice to do a common SELECT without any WHERE.

See there is an update atribute to perform against just pulled rows. Your SELECT must be adjusted with a WHERE to take only those rows which have not been updated before.

See more info in docs: https://docs.spring.io/spring-integration/reference/html/jdbc.html#jdbc-inbound-channel-adapter

huangapple
  • 本文由 发表于 2023年2月8日 13:17:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75381609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定