简体   繁体   English

使用Oracle数据库更改通知检测更改

[英]Detecting changes using Oracle Database Change Notification

I am using oracle.jdbc.dcn.DatabaseChangeListener to record inserts/updates/deletes to a table. 我正在使用oracle.jdbc.dcn.DatabaseChangeListener记录对表的插入/更新/删除。 For inserts, I can keep track of the rowids. 对于插入,我可以跟踪rowid。 However, I am having a problem with updates and deletes. 但是,我在更新和删除时遇到问题。

For updates, I am looking for a way to find out the value of the row/column before the update as made. 对于更新,我正在寻找一种在进行更新之前找出行/列的值的方法。

For deletes, I get the rowid that was deleted, but that is all I get. 对于删除,我得到已删除的rowid,但这就是我得到的全部。 I would like some sort of ability to track which row was deleted. 我想要某种跟踪删除哪一行的功能。

I am setting the properties using oracle.jdbc.OracleConnection . 我正在使用oracle.jdbc.OracleConnection设置属性。

Properties changeNotifProps = new Properties();
changeNotifProps.put(OracleConnection.DCN_IGNORE_DELETEOP,"false");             
changeNotifProps.put(OracleConnection.DCN_IGNORE_INSERTOP, "false");
changeNotifProps.put(OracleConnection.DCN_IGNORE_UPDATEOP , "false");
changeNotifProps.put(OracleConnection.DCN_NOTIFY_CHANGELAG , "0");
changeNotifProps.put(OracleConnection.DCN_NOTIFY_ROWIDS , "true");
changeNotifProps.put(OracleConnection.NTF_LOCAL_HOST , <hostname>);
changeNotifProps.put(OracleConnection.NTF_LOCAL_TCP_PORT , "7115");
return changeNotifProps;

Is there some sort of property I can set to detect the previous value of the rows? 我可以设置某种属性来检测行的先前值吗?

EDIT: I forgot to mention that I am doing this on hundreds of tables. 编辑:我忘了提到我正在数百个表上执行此操作。 I can't add triggers/tables to log the change. 我无法添加触发器/表来记录更改。 I need to record all the changes in the JVM. 我需要在JVM中记录所有更改。

Create an audit table and use an AFTER INSERT UPDATE DELETE trigger to populate it. 创建一个审计表,并使用AFTER INSERT UPDATE DELETE触发器填充它。 I like to log the key (you could log the ROWID here), the time and date, the user, the SQL verb (INSERT, UPDATE, DELETE) and the appropriate values (use the NEW values on INSERT and UPDATE, use the OLD values when logging a DELETE). 我喜欢记录密钥(您可以在此处记录ROWID),时间和日期,用户,SQL动词(INSERT,UPDATE,DELETE)和适当的值(在INSERT和UPDATE上使用NEW值,在OLD上使用记录删除时的值)。 Given this you should be able to retrieve your values from the audit table. 鉴于此,您应该能够从审核表中检索值。

Share and enjoy. 分享并享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM