Skip to content

Commit

Permalink
AC-2499: make sure any ERXEnterpriseObjectCache initalized after the …
Browse files Browse the repository at this point in the history
…app has launched listen for editingContextDidSaveChanges

Signed-off-by: Tom Philip <tphilip@omtay.org>
  • Loading branch information
omtay committed Jul 9, 2015
1 parent 321ad03 commit 9c6b3f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import er.extensions.eof.ERXDatabaseContextMulticastingDelegate;
import er.extensions.eof.ERXEC;
import er.extensions.eof.ERXEOAccessUtilities;
import er.extensions.eof.ERXEnterpriseObjectCache;
import er.extensions.eof.ERXEntityClassDescription;
import er.extensions.eof.ERXGenericRecord;
import er.extensions.eof.ERXModelGroup;
Expand Down Expand Up @@ -295,6 +296,13 @@ public void finishInitialization() {
ERXObjectStoreCoordinatorPool.initializeIfNecessary();
}

@Override
public void didFinishInitialization() {
ERXEnterpriseObjectCache.setDidFinishInitialization(true);

super.didFinishInitialization();
}

private static Map<String, Support> _qualifierKeys;

public static synchronized void registerSQLSupportForSelector(NSSelector selector, EOQualifierSQLGeneration.Support support) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.webobjects.foundation.NSNotificationCenter;
import com.webobjects.foundation.NSSelector;

import er.extensions.appserver.ERXApplication;
import er.extensions.foundation.ERXExpiringCache;
import er.extensions.foundation.ERXSelectorUtilities;

Expand Down Expand Up @@ -88,9 +87,10 @@ public class ERXEnterpriseObjectCache<T extends EOEnterpriseObject> {
private boolean _returnUnsavedObjects;

/** If <code>false</code>, the cache is not allowed to fetch values as migrations may not have been processed yet.
* @see ERXApplication#ApplicationDidFinishInitializationNotification
* @see er.extensions.ERXExtensions#finishInitialization
* @see #setDidFinishInitialization(boolean)
*/
private boolean _applicationDidFinishInitialization;
private static boolean _applicationDidFinishInitialization;

/**
* Creates the cache for the given entity name and the given keypath. No
Expand Down Expand Up @@ -159,7 +159,7 @@ public ERXEnterpriseObjectCache(String entityName, String keyPath, EOQualifier q
_qualifier = qualifier;
_resetOnChange = true; // MS: for backwards compatibility
_fetchInitialValues = true; // MS: for backwards compatibility
_applicationDidFinishInitialization = false;
// _applicationDidFinishInitialization = false;
start();
}

Expand Down Expand Up @@ -205,7 +205,7 @@ public ERXEnterpriseObjectCache(String entityName, String keyPath, EOQualifier q
_timeout = timeout;
_qualifier = qualifier;
_returnUnsavedObjects = shouldReturnUnsavedObjects;
_applicationDidFinishInitialization = false;
// _applicationDidFinishInitialization = false;
setRetainObjects(shouldRetainObjects);
setResetOnChange(false);
setFetchInitialValues(shouldFetchInitialValues);
Expand All @@ -218,13 +218,8 @@ public ERXEnterpriseObjectCache(String entityName, String keyPath, EOQualifier q
* @see #stop()
*/
public void start() {
// Catch this to disable caching before application did finish to start (and most importantly processed migrations)
NSSelector selector = ERXSelectorUtilities.notificationSelector("enableFetchingOfInitialValues");
NSNotificationCenter.defaultCenter().addObserver(this, selector,
ERXApplication.ApplicationDidFinishInitializationNotification, null);

// Catch this to update the cache when an object is changed
selector = ERXSelectorUtilities.notificationSelector("editingContextDidSaveChanges");
NSSelector selector = ERXSelectorUtilities.notificationSelector("editingContextDidSaveChanges");
NSNotificationCenter.defaultCenter().addObserver(this, selector,
EOEditingContext.EditingContextDidSaveChangesNotification, null);

Expand All @@ -243,7 +238,6 @@ public void start() {
* @see #start()
*/
public void stop() {
NSNotificationCenter.defaultCenter().removeObserver(this, ERXApplication.ApplicationDidFinishInitializationNotification, null);
NSNotificationCenter.defaultCenter().removeObserver(this, EOEditingContext.EditingContextDidSaveChangesNotification, null);
NSNotificationCenter.defaultCenter().removeObserver(this, ERXEnterpriseObjectCache.ClearCachesNotification, null);
_cache.stopBackgroundExpiration();
Expand Down Expand Up @@ -346,17 +340,6 @@ public void clearCaches(NSNotification n) {
}
}

/**
* Handler for the ApplicationDidFinishInitializationNotification notification. Enables the fetching of initial
* values and such ensure that any migrations have been processed before.
* @param n notification that is fired in ERXApplication.finishInitialization
*/
public void enableFetchingOfInitialValues(NSNotification n) {
_applicationDidFinishInitialization = true;
NSNotificationCenter.defaultCenter().removeObserver(this,
ERXApplication.ApplicationDidFinishInitializationNotification, null);
}

/**
* @return the name of the EOEntity this cache is for
*/
Expand Down Expand Up @@ -842,4 +825,12 @@ public EORecord(@SuppressWarnings("hiding") EOGlobalID gid, @SuppressWarnings("h
this.eo = eo;
}
}

/**
* called from {@link er.extensions.ERXExtensions#finishInitialization(NSNotification)}
* @param didFinish
*/
public static void setDidFinishInitialization(boolean didFinish) {
_applicationDidFinishInitialization = didFinish;
}
}

0 comments on commit 9c6b3f9

Please sign in to comment.