Oracle 表更改监视器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/337335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:31:47  来源:igfitidea点击:

Oracle table change monitor

javaoracle

提问by LenW

I have a java application that is connected to a view on a remote Oracle db.

我有一个连接到远程 Oracle 数据库上的视图的 Java 应用程序。

Does anyone know of a way in Java to monitor this table for changes? I.e. if there are inserts of updates etc I would need to react.

有谁知道在 Java 中监视此表的更改的方法?即,如果有更新等的插入,我需要做出反应。

采纳答案by ShoeLace

You can place a INSERT/UPDATE/DELETE trigger on the table to perform some action when 'data' changes are made to the table. (as opposed to changes to the structure of the table)

您可以在表上放置一个 INSERT/UPDATE/DELETE 触发器,以便在对表进行“数据”更改时执行某些操作。(与表格结构的变化相反)

I believe 10g also supports triggers on views.

我相信 10g 也支持视图触发器。

but I'm not sure how you can notifiy the java process of this other then by polling.

但我不确定您如何通过轮询来通知其他人的 Java 进程。

sorry.

对不起。

you could possibly create some solution where the java app has a 'listen' server and the database pushes it back a message. but that sounds hard to maintain.

您可能会创建一些解决方案,其中 Java 应用程序具有“侦听”服务器并且数据库将其推回消息。但这听起来很难维持。

Justin Cavein the comments suggests you could configure Oracle Streams to send out logical change records (LCRs) that a Java app could subscribe to via JMS. Or the trigger could write records to an Advanced Queue that Java could subscribe to via JMS.

评论中的Justin Cave建议您可以配置 Oracle Streams 以发送 Java 应用程序可以通过 JMS 订阅的逻辑更改记录 (LCR)。或者触发器可以将记录写入 Java 可以通过 JMS 订阅的高级队列。

you will still need to be wary of Oracle transations.. due to the way Oracle transactions work, the trigger will fire on the change, but it may also fire multiple times..

您仍然需要警惕 Oracle 事务……由于 Oracle 事务的工作方式,触发器将在更改时触发,但也可能多次触发。

and in anycase the java app would not bee able to 'see' the changes until a commit had been performed.

无论如何,在执行提交之前,Java 应用程序将无法“看到”更改。

回答by FerranB

Look at Oracle Change Notification, a so interesting Oracle feature.

看看Oracle Change Notification,这是一个非常有趣的 Oracle 特性。

From the Oracle documentation: "Database Change Notification is a feature that enables client applications to register queries with the database and receive notifications in response to DML or DDL changes on the objects associated with the queries. The notifications are published by the database when the DML or DDL transaction commits."

来自 Oracle 文档:“数据库更改通知是一项功能,它使客户端应用程序能够向数据库注册查询并接收通知以响应与查询关联的对象的 DML 或 DDL 更改。通知由数据库发布,当 DML或 DDL 事务提交。”