我有一个spring-integration message channel,它使用jpa inbound-channel-adapter从数据库中读取。
<int:channel id="logChannel">
<int:priority-queue capacity="20" />
</int:channel>
<int-jpa:inbound-channel-adapter
channel="logChannel" entity-class="com.objects.Transactionlog"
entity-manager-factory="entityManagerFactory" auto-startup="true"
jpa-query="SELECT x FROM Transactionlog AS x WHERE x.status LIKE '1'" max-results="1">
<int:poller fixed-rate="5000">
<int:transactional propagation="REQUIRED"
transaction-manager="transactionManager" />
</int:poller>
</int-jpa:inbound-channel-adapter>这总是只读取表transactionlog的第一行。因此,我想在读取后更新每个数据库条目的status。有人知道怎么做吗?
发布于 2014-05-12 07:48:58
如果max-results="1"对您来说没有问题,并且每5秒只接收一个实体,那么就让它成为您的用例吧。
现在如何更新该实体以在下一次投票中跳过它。
<int-jpa:inbound-channel-adapter>有delete-after-poll="true"选项,允许在实体检索之后执行entityManager.remove(entity)。
对,这才是真正的从DB中移除。若要将其转换为更新,可以将实体标记为:
@SQLDelete(sql = "UPDATE Transactionlog SET status = false WHERE id = ?")或者类似的东西,这是对你的赞许。
另一个特性是事务同步,当您用一些before-commit工厂标记<poller>并在那里进行更新时。类似于:
<int-jpa:inbound-channel-adapter ...>
<int:poller fixed-rate="5000">
<int:transactional propagation="REQUIRED"
transaction-manager="transactionManager"
synchronization-factory="txSyncFactory" />
</int:poller>
<int-jpa:inbound-channel-adapter>
<int:transaction-synchronization-factory id="txSyncFactory">
<int:before-commit channel="updateEntityChannel" />
</int:transaction-synchronization-factory>
<int:chain input-channel="updateEntityChannel">
<int:enricher>
<int:property name="status" value="true"/>
</int:enricher>
<int-jpa:outbound-channel-adapter entity-manager="entityManager"/>
</int:chain/>差不多吧。
https://stackoverflow.com/questions/23602591
复制相似问题