spring-integration - Spring 集成 JDBC 轮询器。使用复合主键更新
问题描述
我正在使用 JDBC 轮询器来处理一些数据库记录,当工作流完成时,我需要更新这些记录。如果适用于具有复合键的表,我找不到一种方法。
这是我的例子。表事件。带有主键(DATETIME、EVENT_LOCATION、EVENT_TYPE)。我无法更改架构。
行映射到具有属性名称的 POJO:日期时间、位置、类型。
<int-jdbc:inbound-channel-adapter
query="select * from events where uploaded = 0”
channel="fromdb" data-source="dataSource"
max-rows="${app.maxrows}"
row-mapper=“eventRowMapper”
update="update events set uploaded=1 where DATETIME =:dateTime AND EVENT_LOCATION=:location AND EVENT_TYPE = :type”>
<int:poller fixed-delay="${app.intervalmsecs}" />
但是当轮询器尝试更新这些记录时,我从服务器收到语法错误响应。
阅读文档后,轮询器似乎使用 '(:id)' 来更新 rows ,但它假设一个单列 PK。我找不到任何有关更新主键中包含多列的行的信息
有没有办法用多列主键更新行?或者我应该使用出站 jdbc 还是编写自己的更新解决方案?
解决方案
显示完整的堆栈跟踪;您的事件对象和行映射器;我刚刚更改了其中一项测试
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(embeddedDatabase,
"select * from item where id not in (select id from copy)");
adapter.setUpdateSql("insert into copy values(:id,10)");
到
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(embeddedDatabase,
"select * from item where id not in (select foo from copy)");
adapter.setUpdateSql("insert into copy values(:foo,:status)");
它工作得很好。
只要该列作为选择查询结果的属性出现,它就会起作用。(结果是由行映射器创建的对象)。
即dateTime
,location
并且type
必须是 上的属性Event
。
此外,根据您的update-query
,看起来您应该update-per-row
设置为 true ,因为它只更新一行。
推荐阅读
- c - 在C中同时读取命令行和recvfrom
- database - 错误:列“own_amount”的类型为数字,但表达式的类型为字符变化
- sql - 在 BigQuery/Standard SQL 中使用数组确定给定日期的状态
- swift - 如何解决 UIResponder 无法识别的问题?
- user-interface - 有人可以解释如何添加滑块对象以控制自己的伺服电机吗?
- python - Plotly-Dash:3 个回调,相同的输入列表 - 2 个被调用,1 个不被调用
- login - Identity Server 4 注册用户后自动登录
- java - Firebase MLKit 可以用来检测多边形吗?
- c++ - 通过 C++ 单击按钮后更新 QML TableView
- visual-studio-code - 由于“代码 - Insiders.exe”上的访问被拒绝错误,安装和更新失败