英文:
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
<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>
答案1
得分: 0
它在每次轮询周期都调用 query="SELECT * FROM Accounts"
,并提取 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="SELECT * FROM Accounts"
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论