NSArray<Employee> holdingOnToEmployees = company_osc2.employees();
assertEquals(2, holdingOnToEmployees.count());
for (Employee employee : holdingOnToEmployees) {
assertNotNull(employee);
assertNotNull(employee.name());
}
NSArray<Employee> holdingOnToUntouchedEmployees = company_osc2.employees();
assertEquals(2, holdingOnToUntouchedEmployees.count());
// Delete Employee1 in OSC1 and Save
editingContext_osc1.deleteObject(employee1_osc1);
editingContext_osc1.saveChanges();
sleep();
// Test that the deleted object is technically still in our EC
assertEquals(2, holdingOnToEmployees.count());
for (Employee employee : holdingOnToEmployees) {
assertNotNull(employee);
assertNotNull(employee.name());
}
// Test that the deleted object is technically still in our EC
assertEquals(2, holdingOnToUntouchedEmployees.count());
for (Employee employee : holdingOnToUntouchedEmployees) {
assertNotNull(employee);
assertNotNull(employee.name());
}
for (Employee employee : holdingOnToEmployees) {
employee.setName(employee.name() + " Modified");
}
try {
editingContext_osc2.saveChanges();
throw new AssertionFailedError("This should have failed.");
}
catch (EOGeneralAdaptorException e) {
// expected
}
// Fetch and check employees for Company1 in OSC1
assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee2_osc1 }), company_osc1.employees());
// Fetch and check employees for Company1 in OSC2
assertContainsExactlyEOs(new NSArray<Employee>(new Employee[] { employee2_osc1 }), company_osc2.employees());
So once it's already fetched. you hold a fetched reference to the EO. When the object is deleted from object store 1, it's still in your fetched array (and it's verifying it's non-null and contains data). If, however, you fetch the employees() array AGAIN, it is now gone from the array. I believe this is testing your scenario. Now, if you try to MESS with that EO (as in the example), you're going to get an adaptor exception ("updateValuesInRowDescribedByQualifier -- com.webobjects.jdbcadaptor.JDBCChannel method failed to update row in database") because the original EO is gone, but I suspect this is a little easier to deal with than your random null.