EOEditingContext ec1 = ERXEC.newEditingContext(osc);
EOEditingContext ec2 = ERXEC.newEditingContext(osc);
// Fetch again into this ec to ensure snapshots are in the database
Company c;
// Expect relationship to be a fault
Object relationshipValue;
ec1.lock();
try {
// Fetch Company with cGid
c = (Company) ec1.faultForGlobalID(cGid, ec1);
// c will be a fault
assertTrue(EOFaultHandler.isFault(c));
relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
// c will no longer be a fault
assertFalse(EOFaultHandler.isFault(c));
// relationshipValue will be a fault
assertTrue(EOFaultHandler.isFault(relationshipValue));
// Fire the fault to fetch and to ensure snapshot is registered in eodb
ERXTestUtilities.fireFault(relationshipValue);
// -----------------------------------------
// Fetch Company with cGid0
c = (Company) ec1.faultForGlobalID(cGid0, ec1);
relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
assertTrue(EOFaultHandler.isFault(relationshipValue));
// Fire the fault to fetch and to ensure snapshot is registered in eodb
ERXTestUtilities.fireFault(relationshipValue);
} finally {
ec1.unlock();
}
// Fetch
ec2.lock();
try {
// Fetch Company with cGid
c = (Company) ec2.faultForGlobalID(cGid, ec2);
// Expect relationship to be a fault
relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
assertTrue(EOFaultHandler.isFault(relationshipValue));
// There will be a snapshot in the db
NSArray toManySnapshot = ERXTestUtilities.snapshotArrayForRelationshipInObject(c, Company.EMPLOYEES_KEY);
assertNotNull(toManySnapshot);
// Count will come from snapshot cache
Integer count = ERXEOControlUtilities.objectCountForToManyRelationship(c, Company.EMPLOYEES_KEY);
assertEquals(3, count.intValue());
// -----------------------------------------
// Fetch Company with cGid0
c = (Company) ec2.faultForGlobalID(cGid0, ec2);
// Expect relationship to be a fault
relationshipValue = c.storedValueForKey(Company.EMPLOYEES_KEY);
assertTrue(EOFaultHandler.isFault(relationshipValue));
// There will be a snapshot in the db
toManySnapshot = ERXTestUtilities.snapshotArrayForRelationshipInObject(c, Company.EMPLOYEES_KEY);
assertNotNull(toManySnapshot);