* @param relationshipName relationship name
* @param database database object
*/
public static void clearSnapshotForRelationshipNamedInDatabase(EOEnterpriseObject eo, String relationshipName, EODatabase database) {
EOEditingContext ec = eo.editingContext();
EOObjectStoreCoordinator osc = (EOObjectStoreCoordinator) ec.rootObjectStore();
osc.lock();
try {
EOGlobalID gid = ec.globalIDForObject(eo);
database.recordSnapshotForSourceGlobalID(null, gid, relationshipName);
Object o = eo.storedValueForKey(relationshipName);
boolean needRefresh = false;
if(o instanceof EOFaulting) {
EOFaulting toManyArray = (EOFaulting)o;
if (!toManyArray.isFault()) {
EOFaulting tmpToManyArray = (EOFaulting)((EOObjectStoreCoordinator)ec.rootObjectStore()).arrayFaultWithSourceGlobalID(gid, relationshipName, ec);
toManyArray.turnIntoFault(tmpToManyArray.faultHandler());
needRefresh = true;
}
} else {
EOFaulting tmpToManyArray = (EOFaulting)((EOObjectStoreCoordinator)ec.rootObjectStore()).arrayFaultWithSourceGlobalID(gid, relationshipName, ec);
eo.takeStoredValueForKey(tmpToManyArray, relationshipName);
needRefresh = true;
}
if(needRefresh && (eo instanceof ERXEnterpriseObject)) {
((ERXEnterpriseObject)eo).flushCaches();
}
}
finally {
osc.unlock();
}
}