// MOVEME: ERXEOFUtilities
public static void refreshSharedObjectsWithName(String entityName) {
if (entityName == null) {
throw new IllegalArgumentException("Entity name argument is null for method: refreshSharedObjectsWithName");
}
EOSharedEditingContext sharedEC = EOSharedEditingContext.defaultSharedEditingContext();
sharedEC.lock();
try {
EOEntity entity = ERXEOAccessUtilities.entityNamed(sharedEC, entityName);
if (entity == null) {
_log.warn("Attempting to refresh a non-existent (or not accessible) EO: " + entityName);
return;
}
//if entity caches objects, clear out the cache
if( entity.cachesObjects() ) {
EODatabaseContext databaseContext = EOUtilities.databaseContextForModelNamed(sharedEC, entity.model().name());
EODatabase database = databaseContext.database();
database.invalidateResultCacheForEntityNamed(entityName);
}
NSArray fetchSpecNames = entity.sharedObjectFetchSpecificationNames();
int count = (fetchSpecNames != null) ? fetchSpecNames.count() : 0;
if ( count > 0 ) { //same check as ERXEOAccessUtilities.entityWithNamedIsShared(), but avoids duplicate work
for (int index = 0 ; index < count ; ++index) {
String oneFetchSpecName = (String)fetchSpecNames.objectAtIndex(index);
EOFetchSpecification fs = entity.fetchSpecificationNamed(oneFetchSpecName);
if (fs != null) {
fs.setRefreshesRefetchedObjects(true);
sharedEC.bindObjectsWithFetchSpecification(fs, oneFetchSpecName);
}
}
//notify the entity class, if it wants to know
String className = entity.className();
Class entityClass = Class.forName(className);
if (_sharedEntityDataWasRefreshedSelector.implementedByClass(entityClass)) {
_sharedEntityDataWasRefreshedSelector.invoke(entityClass);
}
} else {
_log.warn("Attempting to refresh a non-shared EO: " + entityName);
}
} catch (Exception e) {
throw new NSForwardException(e, "Exception while refreshing shared objects for entity named " + entityName);
} finally {
sharedEC.unlock();
}
}