Re: Infinite Loop in Editing Context
Re: Infinite Loop in Editing Context
- Subject: Re: Infinite Loop in Editing Context
- From: Chuck Hill <email@hidden>
- Date: Thu, 22 Jan 2004 12:12:34 -0800
There is no need to send the same message over and over to all the lists.
Be patient.
First off, this
EOEditingContext ec = (EOEditingContext)notification.object();
//Create a nested editing context
EOEditingContext localEC = new EOEditingContext();
does NOT create a nested editing context. This does:
EOEditingContext ec = (EOEditingContext)notification.object();
//Create a nested editing context
EOEditingContext localEC = new EOEditingContext(ec);
Second, you're not locking the nested ec. Bad.
Third, EditingContextDidSaveChangesNotification gets sent for all changes
in all editing contexts. I'll guess it also gets sent for the ActivityLog.
You will probably want to inspect the notification a little more closely
before deciding to create an ActivityLog.
Chuck
At 02:26 PM 22/01/2004 -0500, Bobbie Daniels wrote:
>List,
>
>I need to add a row to the database when a user edits or updates certain
>fields in the application. From this, I will generate a report showing the
>edited or updated fields. The method is saving the updates and adding a row,
>but it is in an infinite loop, so instead of getting only one row, I get
>many, many rows. Does anyone have any idea why this method keeps getting
>called? This is a Direct to Java Client Application, using EOS and a Custom
>Controller.
>
>**This is the code in the client side of the entity.
>
>public Object appendActivityLog(NSDictionary args) {
> return invokeRemoteMethod("clientSideRequestAppendActivityLog", new
>Class[] {NSDictionary.class}, new Object[] {args});
> }
>
>
>**This is the code in the server side of the entity.
>
>public Object clientSideRequestAppendActivityLog(NSDictionary args) {
> return appendActivityLog(args);
> }
>
> public Object appendActivityLog(NSDictionary args) {
> EOEditingContext ec = editingContext();
> try {
> //Create the ActivityLog and initalize here
> ActivityLog newLog =
>(ActivityLog)EOUtilities.createAndInsertInstance(ec, "ActivityLog");
> newLog.appendln(args);
> ec.saveChanges();
> }
> catch(Exception ex) {
> NSLog.out.appendln("Failed to save ActivityLog: " +
>ex.getMessage());
> }
> return null;
> }
>
>
>**This is the code in the Custom Controller.
>
>public class CustomClaimantFormController extends EOFormController {
>
> public CustomClaimantFormController(EOXMLUnarchiver unarchiver) {
> super(unarchiver);
> NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
> nc.addObserver(this, new NSSelector("logUserChanges", new Class[] {
>NSNotification.class}),
>EOEditingContext.EditingContextDidSaveChangesNotification,
>editingContext());
> }
>
> public void logUserChanges(NSNotification notification) {
> //Get the EditingContext from the Notification
> EOEditingContext ec = (EOEditingContext)notification.object();
> //Create a nested editing context
> EOEditingContext localEC = new EOEditingContext();
> //Append to the ActivityLog here
> EOGlobalID personGID =
>AuthenticationCenter.sharedAuthenticationCenter().userGlobalID();
> User user = (User)(localEC.faultForGlobalID(personGID, ec));
> EOGlobalID claimantGID = ec.globalIDForObject(selectedObject());
> Claimant claimant = (Claimant)localEC.faultForGlobalID(claimantGID,
>ec);
> NSMutableDictionary args = new NSMutableDictionary();
> args.setObjectForKey(user, "user");
> args.setObjectForKey(claimant, "claimant");
> args.setObjectForKey(claimant.amount(), "amount");
> claimant.appendActivityLog(args);
> localEC.saveChanges();
> }
>}
>_______________________________________________
>webobjects-dev mailing list | email@hidden
>Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>Do not post admin requests to the list. They will be ignored.
>
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.