}
}
Accessor accessor = databaseSession.getAccessor();
accessor.incrementCallCount(databaseSession);
try {
OracleConnection connection = (OracleConnection)databaseSession.getServerPlatform().unwrapConnection(accessor.getConnection());
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_registering");
Properties properties = new Properties();
properties.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
properties.setProperty(OracleConnection.DCN_IGNORE_INSERTOP, "true");
try {
// Register with the database change notification, the connection is not relevant, the events occur after the connection is closed,
// and a different connection can be used to unregister the event listener.
this.register = connection.registerDatabaseChangeNotification(properties);
final List<DatabaseField> fields = new ArrayList<DatabaseField>();
fields.add(new DatabaseField(ROWID));
this.register.addListener(new DatabaseChangeListener() {
public void onDatabaseChangeNotification(DatabaseChangeEvent changeEvent) {
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_change_event", changeEvent);
if (changeEvent.getTableChangeDescription() != null) {
for (TableChangeDescription tableChange : changeEvent.getTableChangeDescription()) {
ClassDescriptor descriptor = OracleChangeNotificationListener.this.descriptorsByTable.get(new DatabaseTable(tableChange.getTableName()));
if (descriptor != null) {
CacheIndex index = descriptor.getCachePolicy().getCacheIndex(fields);
for (RowChangeDescription rowChange : tableChange.getRowChangeDescription()) {
CacheId id = new CacheId(new Object[]{rowChange.getRowid().stringValue()});
CacheKey key = databaseSession.getIdentityMapAccessorInstance().getIdentityMapManager().getCacheKeyByIndex(
index, id, true, descriptor);
if (key != null) {
if ((key.getTransactionId() == null) || !key.getTransactionId().equals(changeEvent.getTransactionId(true))) {
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_invalidate", key.getKey(), descriptor.getJavaClass().getName());
key.setInvalidationState(CacheKey.CACHE_KEY_INVALID);
}
}
}
}
}
}
}
});
// Register each table for database events, this is done by executing a select from the table.
for (DatabaseTable table : this.descriptorsByTable.keySet()) {
OracleStatement statement = (OracleStatement)connection.createStatement();
statement.setDatabaseChangeRegistration(this.register);
try {
statement.executeQuery("SELECT ROWID FROM " + table.getQualifiedName()).close();
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_register_table", table.getQualifiedName());
} catch (Exception failed) {