Created
June 16, 2016 15:38
-
-
Save krisrice/c1109366b3ffbfa1f380c6835ba68116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DatabaseChangeListener = Java.type("oracle.jdbc.dcn.DatabaseChangeListener"); | |
var Properties = Java.type("java.util.Properties"); | |
var OracleConnection = Java.type("oracle.jdbc.OracleConnection"); | |
var OracleStatement = Java.type("oracle.jdbc.OracleStatement"); | |
var cmd = {}; | |
cmd.onChange = function(e){ | |
// print it out but could go query the change instead | |
ctx.write("\n Data Changed:" + e.toString() + "\n"); | |
out.flush(); | |
} | |
var MyChangeListener = Java.extend(DatabaseChangeListener, { | |
onDatabaseChangeNotification : cmd.onChange | |
}); | |
var prop = new Properties(); | |
prop.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS,"true"); | |
prop.setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION,"true"); | |
var dcr = conn.registerDatabaseChangeNotification(prop); | |
var changeListener = new MyChangeListener(); | |
dcr.addListener(changeListener); | |
var stmt = conn.createStatement(); | |
// associate the statement with the registration: | |
stmt.setDatabaseChangeRegistration(dcr); | |
// build up the sql again | |
var sql=""; | |
for(var i=1;i<args.length;i++){ | |
sql = sql + " " + args[i]; | |
} | |
ctx.write(sql + "\n\n"); | |
var rs = stmt.executeQuery(sql); | |
ctx.write("\nRegistered\n") | |
var tableNames = dcr.getTables(); | |
for(var i=0;i<tableNames.length;i++) | |
ctx.write(tableNames[i]+" is part of the registration.\n"); | |
stmt.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment