Registration Properties
Properties props = new Properties();
props.put(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
props.put(OracleConnection.NTF_QOS_RELIABLE, "false");
props.setProperty(OracleConnection.DCN_BEST_EFFORT, "true");
DatabaseChangeRegistration dcr =
conn.registerDatabaseChangeNotification(props);
Listener Class
package pas.jdbc;
import oracle.jdbc.dcn.DatabaseChangeEvent;
import oracle.jdbc.dcn.DatabaseChangeListener;
import oracle.jdbc.dcn.RowChangeDescription;
import oracle.jdbc.dcn.RowChangeDescription.RowOperation;
import oracle.jdbc.dcn.TableChangeDescription;
public class DCNListener implements DatabaseChangeListener
{
DCNDemo demo;
DCNListener(DCNDemo dem)
{
demo = dem;
}
public void onDatabaseChangeNotification(DatabaseChangeEvent databaseChangeEvent)
{
System.out.println("DCNListener: got an event (" + this + ")");
System.out.println(databaseChangeEvent.toString());
TableChangeDescription [] tableChanges =
databaseChangeEvent.getTableChangeDescription();
for (TableChangeDescription tableChange : tableChanges)
{
RowChangeDescription[] rcds = tableChange.getRowChangeDescription();
for (RowChangeDescription rcd : rcds)
{
System.out.println("Affected row -> " + rcd.getRowid().stringValue());
RowOperation ro = rcd.getRowOperation();
if (ro.equals(RowOperation.INSERT))
{
System.out.println("INSERT occurred");
}
else if (ro.equals(RowOperation.UPDATE))
{
System.out.println("UPDATE occurred");
}
else if (ro.equals(RowOperation.DELETE))
{
System.out.println("DELETE occurred");
}
else
{
System.out.println("Not a INSERT/DELETE/UPDATE change");
}
}
}
synchronized( demo )
{
demo.notify();
}
}
No comments:
Post a Comment