• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Infinite Loop in Editing Context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Infinite Loop in Editing Context


  • Subject: Re: Infinite Loop in Editing Context
  • From: Robert Walker <email@hidden>
  • Date: Thu, 22 Jan 2004 17:56:51 -0500

Chuck,

Bobbie works in my office and I've been trying to help her with this issue. Unfortunately, it is slightly over my head as well.

Let me see if I can clarify the issue a bit further and explain what we are attempting to accomplish.

Our client requires change auditing on a Direct to Java Client application. This is quite easy to accomplish with a web application, but we are having some trouble getting this to work on the client application.

What we need to accomplish is this:
1. We need to monitor selected attributes on certain entities.
2. When a change is detected we need to log the date/time of the change, the entity affected, the attribute changed, the changed value, and the user making the change. We plan to store the log messages in a database table (ActivityLog). It would also be nice if we could log the old value as well as the new one.


Since we need to create this log message after the change is successfully committed to the database we must detect the successful ec.saveChanges() message.

On a web application I might do something like this:
try {
	EOEditingContext ec;  //assume this exists
	ec.saveChanges();
	//Create the ActivityLog here with the auditing info
}
catch (Exception exception) {
	//Handle the exception here
}

In our Java Client application we have attempted to use the delegate method editingContextWillSaveChanges(). We decided this wouldn't work because it is called before a successful save. So we tried using the notification EditingContextDidSaveChangesNotification.

In both cases we had problems with the system getting into an infinite event loop cycle. Creating the ActivityLog causes both the delegate method and the notification to be called/posted infinitely.

There must be a way to accomplish this, but I just haven't been able to figure it out.

Any an all assistance would be greatly appreciated.

Thanks in advance:
Robert Walker

P.S. :
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);
I'm sure this was an outdated comment line since we tried multiple techniques to resolve this issue.

On Jan 22, 2004, at 3:12 PM, Chuck Hill wrote:

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.
_______________________________________________
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.

References: 
 >Re: Infinite Loop in Editing Context (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: command line options in PB OSX?
  • Next by Date: Problem with hostname resolution
  • Previous by thread: Re: Infinite Loop in Editing Context
  • Next by thread: command line options in PB OSX?
  • Index(es):
    • Date
    • Thread