Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix issues with disappearing snapshots when using nested ecs #342

Merged
merged 1 commit into from
Jan 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public class ERXEC extends EOEditingContext {
private static final NSSelector EditingContextWillRevertObjectsDelegateSelector = new NSSelector("editingContextWillRevertObjects", new Class[] { EOEditingContext.class, NSArray.class, NSArray.class, NSArray.class });
private static final NSSelector EditingContextDidRevertObjectsDelegateSelector = new NSSelector("editingContextDidRevertObjects", new Class[] { EOEditingContext.class, NSArray.class, NSArray.class, NSArray.class });
private static final NSSelector EditingContextDidFailSaveChangesDelegateSelector = new NSSelector("editingContextDidFailSaveChanges", new Class[] { EOEditingContext.class, EOGeneralAdaptorException.class });

private static final String ERXECProcessQueuedNotificationsNotification = "processQueuedNotifications";
public static final NSSelector ERXECProcessQueuedNotificationsSelector = ERXSelectorUtilities.notificationSelector("processQueuedNotificationsNotification");

/**
* @return the value of the <code>er.extensions.ERXEC.editingContextClassName</code> property, which
Expand Down Expand Up @@ -1484,7 +1487,20 @@ public Object invokeRemoteMethod(EOEditingContext eoeditingcontext, EOGlobalID e
@Override
public void _objectsChangedInStore(NSNotification nsnotification) {
ERXEnterpriseObject.FlushCachesProcessor.perform(this, (NSArray) nsnotification.userInfo().objectForKey("objects"));
if (savingChanges) {

/*
* Check to see if this context, or any parent context, is saving changes.
* If so, queue up the notifications.
*/
boolean isSavingChanges = savingChanges;
EOObjectStore parent = parentObjectStore();
while(!isSavingChanges && parent instanceof ERXEC) {
ERXEC parentEc = (ERXEC) parent;
isSavingChanges = parentEc.savingChanges;
parent = parentEc.parentObjectStore();
}

if (isSavingChanges) {
synchronized (queuedNotifications) {
queuedNotifications.addObject(nsnotification);
}
Expand Down Expand Up @@ -1567,6 +1583,11 @@ private void processQueuedNotifications() {
for (NSNotification notification : queuedNotificationsClone) {
_objectsChangedInStore(notification);
}
NSNotificationCenter.defaultCenter().postNotification(ERXECProcessQueuedNotificationsNotification, this);
}

public void processQueuedNotificationsNotification(NSNotification n) {
processQueuedNotifications();
}

/**
Expand Down Expand Up @@ -1732,6 +1753,10 @@ public EOEditingContext _newEditingContext(EOObjectStore objectStore, boolean va
ec.unlock();
}
NSNotificationCenter.defaultCenter().postNotification(EditingContextDidCreateNotification, ec);
if(objectStore instanceof ERXEC) {
ERXEC parent = (ERXEC)objectStore;
NSNotificationCenter.defaultCenter().addObserver(ec, ERXECProcessQueuedNotificationsSelector, ERXECProcessQueuedNotificationsNotification, parent);
}
return ec;
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/ERXTest/Sources/er/extensions/eof/ERXECTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import er.erxtest.ERXTestCase;
import er.erxtest.ERXTestUtilities;
import er.erxtest.model.Company;
import er.erxtest.model.Employee;

public class ERXECTest extends ERXTestCase {

Expand Down Expand Up @@ -52,6 +53,30 @@ public void testConstructorWithObjectStore() {
Assert.assertEquals(parentEC3, ec3.parentObjectStore());
}

public void testNestedECs() {
try {
EOEditingContext ec = ERXEC.newEditingContext();
Company c = (Company) EOUtilities.createAndInsertInstance(ec, Company.ENTITY_NAME);
c.setName("Name");
ec.saveChanges();
EOEditingContext nested = ERXEC.newEditingContext(ec);
Company nestC = c.localInstanceIn(nested);
Employee e = (Employee) EOUtilities.createAndInsertInstance(nested, Employee.ENTITY_NAME);
e.setFirstName("First");
e.setLastName("Last");
e.setManager(Boolean.FALSE);
e.addObjectToBothSidesOfRelationshipWithKey(nestC, Employee.COMPANY_KEY);
nested.saveChanges();
ec.saveChanges();
System.gc();
c.delete();
ec.saveChanges();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}

public void testSerializablilty() throws IOException, ClassNotFoundException {
EOEditingContext ec = ERXEC.newEditingContext();
Company.createCompany(ec, "Some fruit company");
Expand Down