log.warn("Model " + model.name() + " failed: " + e.getMessage());
}
if (databaseContext != null) {
databaseContext.lock();
try {
EODatabase database = databaseContext.database();
if (!verifiedDatabases.containsObject(database)) {
Enumeration gidEnum = database.snapshots().keyEnumerator();
while (gidEnum.hasMoreElements()) {
EOGlobalID gid = (EOGlobalID) gidEnum.nextElement();
if (gid instanceof EOKeyGlobalID) {
EOEnterpriseObject eo = null;
EOKeyGlobalID keyGID = (EOKeyGlobalID) gid;
String entityName = keyGID.entityName();
EOEntity entity = modelGroup.entityNamed(entityName);
NSDictionary snapshot = database.snapshotForGlobalID(gid);
if (snapshot != null) {
EOQualifier gidQualifier = entity.qualifierForPrimaryKey(entity.primaryKeyForGlobalID(gid));
EOFetchSpecification gidFetchSpec = new EOFetchSpecification(entityName, gidQualifier, null);
NSMutableDictionary databaseSnapshotClone;
NSMutableDictionary memorySnapshotClone = snapshot.mutableClone();
EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
channel.openChannel();
channel.selectAttributes(entity.attributesToFetch(), gidFetchSpec, false, entity);
try {
databaseSnapshotClone = channel.fetchRow().mutableClone();
}
finally {
channel.cancelFetch();
}
// gidFetchSpec.setRefreshesRefetchedObjects(true);
// NSArray databaseEOs = editingContext.objectsWithFetchSpecification(gidFetchSpec);
if (databaseSnapshotClone == null) {
mismatches.addObject(gid + " was deleted in the database, but the snapshot still exists: " + memorySnapshotClone);
}
else {
// NSMutableDictionary refreshedSnapshotClone =
// database.snapshotForGlobalID(gid).mutableClone();
ERXDictionaryUtilities.removeMatchingEntries(memorySnapshotClone, databaseSnapshotClone);
if (databaseSnapshotClone.count() > 0 || memorySnapshotClone.count() > 0) {
mismatches.addObject(gid + " doesn't match the database: original = " + memorySnapshotClone + "; database = " + databaseSnapshotClone);
}
eo = (EOEnterpriseObject) editingContext.objectsWithFetchSpecification(gidFetchSpec).objectAtIndex(0);
}
}
if (eo != null) {
Enumeration relationshipsEnum = entity.relationships().objectEnumerator();
while (relationshipsEnum.hasMoreElements()) {
EORelationship relationship = (EORelationship) relationshipsEnum.nextElement();
String relationshipName = relationship.name();
NSArray originalDestinationGIDs = database.snapshotForSourceGlobalID(keyGID, relationshipName);
if (originalDestinationGIDs != null) {
NSMutableArray newDestinationGIDs = new NSMutableArray();
EOQualifier qualifier = relationship.qualifierWithSourceRow(database.snapshotForGlobalID(keyGID));
EOFetchSpecification relationshipFetchSpec = new EOFetchSpecification(entityName, qualifier, null);
EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
channel.openChannel();
try {
channel.selectAttributes(relationship.destinationEntity().attributesToFetch(), relationshipFetchSpec, false, relationship.destinationEntity());