• 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: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !


  • Subject: Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !
  • From: Chuck Hill <email@hidden>
  • Date: Fri, 6 Nov 2009 09:34:53 -0800

Hi Mark,

On Nov 6, 2009, at 2:29 AM, Mark Gowdy wrote:
On 5 Nov 2009, at 22:48, Chuck Hill wrote:
On Nov 5, 2009, at 2:33 PM, Mark Gowdy wrote:

Hi,

I am having an strange problem with Wonder's clearSnapshotForRelationshipNamed method.

We have EOs which are related to each other:
RoutingMediaItem   <<--->   RoutingMediaStatus

When I try to get an up-to-date status object and check the results using:

ERXEOControlUtilities .clearSnapshotForRelationshipNamed(routingMediaItem, RoutingMediaItem.TO_ONE_STATUS);

That method is to clear the snapshot for a to-many relationship, not a to-one. For a to-one, just invalidate the object.

*Doh* I'll go the get 'idiot' hat !

:-P


I think this is what you want:
routingMediaItem .editingtContext().refreshObject(routingMediaItem.toOneStatus())



The 'status' object itself will never change, so I probably just want to refresh the 'routingMediaItem' object.


I noticed that you use:
ec.refreshObject(eo);

I have been using:
ERXEOControlUtilities.refaultObject(eo);

Am I inviting doom?

Maybe... The Wonder version seems a bit "dirty" to me:

public static void refaultObject(EOEnterpriseObject eo) {
if (eo != null && !eo.isFault()) {
EOEditingContext ec = eo.editingContext();
NSArray<EOGlobalID> gids = new NSArray<EOGlobalID>(ec.globalIDForObject(eo));
ec.invalidateObjectsWithGlobalIDs(gids);
}
}


That, I think, will discard any local unsaved changes. The refreshObject method will retain them. In most cases there aren't any so it won't matter. However, I have seen odd things happen with refreshObject. Here is what I actually use:


/**
* Forces this object to be re-read from the database; the snapshot and all editing contexts
* holding this object are updated. Merging or overwriting of the changes is then handled by
* the editing context delegate. This method takes no action if the object is pending insertion.
*
* @param anObject the object to be evaluated
* @throws EOObjectNotAvailableException if the object being refreshed has been deleted
*/
public static void refreshObject(EOEnterpriseObject anObject) throws EOObjectNotAvailableException
{
/** require [valid_theObject_param] anObject != null;
[in_ec] anObject.editingContext() != null; **/


// We can't just call editingContext().refreshObject() or editingContext().refaultObject() the object here.
// That will result in fresh data only if the object is in a single editing context.
// This seems like the safest way to get fresh data and inform all of the other
// editing contexts that they need to update.
EOEditingContext ec = anObject.editingContext();
if ( ! ec.insertedObjects().containsObject(anObject))
{
EOQualifier thisObject = EOUtilities.qualifierForEnterpriseObject(ec, anObject);
EOFetchSpecification fetchSpec = new EOFetchSpecification(entityForSelf(anObject).name(), thisObject, NSArray.EmptyArray);
fetchSpec.setRefreshesRefetchedObjects(true);
NSArray results = ec.objectsWithFetchSpecification(fetchSpec);


// If we did not fetch any objects, then it has been deleted. This EOF stack does not know
// this yet, so we need to invalidate the object and then fire the fault to trigger an exception
// (if the dbCtxt delegate throws), otherwise anObject becomes a Dummy Fault EO
if (results.count() == 0)
{
ec.invalidateObjectsWithGlobalIDs(new NSArray(globalID(anObject)));
anObject.willRead();
}
}
}




Chuck



AELog.dbg("- routingMediaItem.status() class = " + routingMediaItem.status().getClass().getName());
AELog.dbg("- routingMediaItem.status().descr() = " + routingMediaItem.status().descr()); // This is line 100 of RoutingMediaBatch, and descr() is a normal string


The first debug prints what you would expect:
- routingMediaItem.status() class  = RoutingMediaStatus

The second line explodes with:
java.lang.ClassCastException: RoutingMediaStatus
at com .webobjects .eoaccess .EODatabaseContext.objectsForSourceGlobalID(EODatabaseContext.java: 3880)
at com .webobjects .eocontrol .EOObjectStoreCoordinator .objectsForSourceGlobalID(EOObjectStoreCoordinator.java:634)
at com .webobjects .eocontrol .EOEditingContext.objectsForSourceGlobalID(EOEditingContext.java: 3923)
at er.extensions.eof.ERXEC.objectsForSourceGlobalID(ERXEC.java: 1182)
at com .webobjects .eoaccess.EODatabaseContext._fireArrayFault(EODatabaseContext.java: 4245)
at com .webobjects .eoaccess .EOAccessArrayFaultHandler .completeInitializationOfObject(EOAccessArrayFaultHandler.java:77)
at com .webobjects.eocontrol.EOCustomObject.willRead(EOCustomObject.java: 1172)
at com.webobjects.eocontrol._EOMutableKnownKeyDictionary $Initializer $ _GenericRecordBinding .valueInObject(_EOMutableKnownKeyDictionary.java:570)
at com .webobjects .eocontrol.EOCustomObject.storedValueForKey(EOCustomObject.java: 1634)
at _RoutingMediaStatus.descr(_RoutingMediaStatus.java:39)
at RoutingMediaBatch.cancel(RoutingMediaBatch.java:100)


I am a little confused as to what I am doing wrong here (or what I have broken).
I thought it might have been some weird AJAX thing, but I replace the AJAX links with normal ones but the problem persists.


Regards,

Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

-- Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects










-- Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects








_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness ! (From: Mark Gowdy <email@hidden>)
 >Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness ! (From: Chuck Hill <email@hidden>)
 >Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness ! (From: Mark Gowdy <email@hidden>)

  • Prev by Date: Re: What is the proper place for frontbasejdbc.jar - JDBC driver to Frontbase on Mac OS X Leopard
  • Next by Date: Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !
  • Previous by thread: Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !
  • Next by thread: Re: ERXEOControlUtilities.clearSnapshotForRelationshipNamed(..) weirdness !
  • Index(es):
    • Date
    • Thread