/**
* @see com.webobjects.eoaccess.EODatabaseContext.Delegate#databaseContextShouldUpdateCurrentSnapshot(com.webobjects.eoaccess.EODatabaseContext, com.webobjects.foundation.NSDictionary, com.webobjects.foundation.NSDictionary, com.webobjects.eocontrol.EOGlobalID, com.webobjects.eoaccess.EODatabaseChannel)
* @see EODatabase#snapshotForGlobalID(EOGlobalID, long)
*/
public NSDictionary databaseContextShouldUpdateCurrentSnapshot(EODatabaseContext dbCtxt, NSDictionary existingSnapshot, NSDictionary fetchedRow, EOGlobalID gid, EODatabaseChannel dbChannel) {
NSDictionary resultSnapshot = (NSDictionary)perform("databaseContextShouldUpdateCurrentSnapshot", dbCtxt, existingSnapshot, fetchedRow, gid, dbChannel, null);
if (resultSnapshot != null) {
return resultSnapshot;
}
/* There is no way for this delegate method to say "do what you normally do". Our two choices for a default return value are
never update the snapshot or always update it. What we want is neither, we want the unchanged EOF behavior. So we
re-implement what EODatabaseChannel would so in the absence of this delegate method: updating of the snapshot depends
whether we are refreshing and on the snapshot's age and the fetchTimestamp of the EC doing the fetching.
*/
try {
// Again with the object rape. EODatabaseChannel.currentEditingContext() is private and the underlying instance variable
// is protected. We need the ec, so we do what we have to...
EOEditingContext ec = (EOEditingContext) currentEditingContext.invoke(dbChannel, new Object[] {});
// Get the snapshot if it has not expired. cachedSnapshot will be null if it has expired
// If not null, it should be the same as the existingSnapshot parameter
NSDictionary cachedSnapshot = dbCtxt.database().snapshotForGlobalID(gid, ec.fetchTimestamp());
// If we are refreshing or the snapshot in the cache has timed out, but the fetched row
// matches the cached snapshot, reset the time stamp by recording the existing snapshot again.
if (existingSnapshot.equals(fetchedRow) && (dbChannel.isRefreshingObjects() || cachedSnapshot == null)) {
dbCtxt.database().recordSnapshotForGlobalID(existingSnapshot, gid);