refetch(), refreshAllObjects(), refaultAllObjects().
refetch(), refreshAllObjects(), refaultAllObjects().
- Subject: refetch(), refreshAllObjects(), refaultAllObjects().
- From: email@hidden
- Date: Mon, 17 Nov 2003 16:27:30 CDT
- Priority: 3 (Normal)
[demime could not interpret encoding binary - treating as plain text]
Hm. I believe I was thinking of refetch(), yes. I didn't realize it had
been deprecated.
Anyone know why? It was such a useful method.
Looking at the documentation now, it appears that refreshAllObjects() is
basically a replacement for refaultAllObjects(). In fact, I can't figure
out what the heck the difference between refreshAllObjects() and
refaultAllObjects() is.
Wait, okay. refaultAllObjects() will not effect inserted, deleted or
updated objects. refreshAllObjects() will do exactly the same thing with
non-modified objects as refault..., and it will ignore deleted and
inserted objects just like refault... BUT: Will do the 'right' thing
with updated objects, instead of ignoring them like the refault... method.
That's my reading of the documentation anyway. Haven't tested it or
anything. But, if that's right, then you should generally use
refreshAllObjects() INSTEAD OF refaultAllObjects().
But as far as refetch() goes... I have no idea why it's been deprecated,
and there seems to be no real replacement. That's too bad, I don't
understand. It was such a potentially useful method, which was only
introduced relatively recently, only to be deprecated. If anyone can shed
some light on that, it would be useful.
I seem to maybe recall someone (Chuck?) saying that refetch() had some
potentially weird bugs in it. Perhaps instead of fixing the bugs,
they've deprecated it. Doh.
--Jonathan
On Mon, 17 Nov 2003 22:00:57 +0100 Jean Pierre Malrieu wrote:
> Thanks a lot, Jonathan, for this very enlightening explanation.
> I have one question though: I can't find in the current documentation
> (5.2) the method refetchAllObjects you are talking about.
> There used to be a "refetch" method in 5.1, now deprecated. Do you mean
> refreshAllObjects instead of refetchAllObjects?
>
> Jean Pierre.
>
>
> Le 17 nov. 03, ` 19:17, email@hidden a icrit :
>
> > On Fri, 14 Nov 2003 23:02:03 +0100 Jean Pierre Malrieu wrote:
> >
> >> But if an item has been added to the to-many relationship by another
> >> application, calling refaultAllObjects() does not update the list of
> >> items in my component.
> >> Is it normal behaviour?
> >> What is the solution?
> >
> > This is tricky, and I don't know a good way around it. First we need
> > to
> > understand how EOF works, and the concept of 'snapshots'. EOF keeps a
> > 'snapshot' for every EOEnterpriseObject (abbreviated "EO"). This
> > snapshot
> > is basically an NSDictionary of that EO's properties and values. The
> > snapshots are used for optimistic locking, as well as for purposes of
> > efficiency. One problem is that these purposes of efficiency will
> > sometimes get in the way of getting fresh data.
> >
> > So now let's think about what refaultAllObjects() does. It will turn
> > all
> > of the EO's currently watched by the given EOEditingContext (EC) into
> > "faults". This means they no longer contain property values, but next
> > time a property value is accessed on a given EO, that EO will be
> > "cleared", and turned back into a full EO with property values. The
> > problem is that ordinarily, the snapshot values will be used, instead
> > of
> > a trip to the db, to resolve these property values. So even before we
> > get to talking about your to-many relationships, refaultAllObjects()
> > may
> > not do what you want---you may end up with less-than-fresh data, if
> > another process has changed the values in the db, but the snapshots do
> > not reflect this.
> >
> > One way to deal with this problem is by setting the fetch timestamp on
> > the EC---this fetch timestamp means "don't accept snapshot values from
> > before this point in time; demand fresh data, and make a trip to the db
> > if neccesary to get it." Another way is to call refetchAllObjects()
> > instead of refaultAllObjects(). refetchAllObjects() means "don't just
> > refault these objects, actually go to the db to get fresh values for
> > all
> > these objects." That could take a while if you have lots of objects in
> > the EC, of course. But even with refetchAllObjects(), that will just
> > refetch objects _currently_ in the EC----objects later put into the EC,
> > perhaps by following a to-one relationship, may still use old
> > 'snapshot'
> > data. So you probably want to pay attention to the fetch timestamp.
> >
> > Now we get to talking about to-many relationships. In addition to the
> > snapshots kept for an EO, seperate snapshots are kept for to-many
> > relationships. These to-many snapshots simply record, for a particular
> > EO, which objects are at the destination of a particular to-many
> > relationship. But in understanding what's going on, it helps to know
> > that these are seperate snapshots kept for to-many relationships, they
> > are not just a part of the EO snapshot.
> >
> > Now, what's happening for you. You call refaultAllObjects(), but then
> > when you access an object, it's using the old cached snapshot values
> > for
> > it's to-many array destinations. Fixing the fetch timestamp _may_ work
> > to fix this---ideally the EC won't accept those old to-many snapshots
> > that are too old for it's fetch timestamp, and will demand a trip to
> > the
> > db to get fresh information. But it's possible this may not
> > work----EOF
> > unfortunately seems to sometimes forget about to-many snapshots in a
> > lot
> > of it's functions, kind of leaves them out, which is a bug. But it's
> > worth a try.
> >
> > Also, refetchAllObjects() does NOT refetch to-many snapshot
> > information,
> > you'll get fresh values for all simple properties in your EOs, but even
> > after calling refetchAllObjects(), the EOs will still be using the
> > possibly old to-many snapshot information. So that won't work.
> >
> > You can manually fetch this information by setting up an
> > EOFetchSpecification with prefetching relationship paths including the
> > relationships you are interested in, and with
> > setRefreshesRefetchedObjects(true). That will definitely work, but
> > it's
> > a pain---and for some types of relationships (like many of those that
> > go
> > from one model to another)---EOF won't let you prefetch relationships.
> >
> > Ben Trumbull has also suggested that you can manually set the to-many
> > snapshot to "null" when you refault your EOs, and then, when the EO's
> > need to re-load to-many destination information, there's no old
> > snapshot
> > there, and EOF will go to the db to get the values. I haven't tried
> > this
> > yet myself. I am at the moment very nervous about doing anything
> > unusual
> > with the EOF stack, since I'm in the middle of trying to solve some
> > very
> > strange bugs involving EOF, and I'd be worried that non-standard things
> > will make things worse.
> >
> > Hope this helps. It's a somewhat confusing topic, but once you
> > understand
> > it, you'll have a knowledge of what EOF is doing that is very valuable
> > when working with EOF.
> >
> > You may also be interested to see some other comments on similar
> > issues at:
> > http://wodev.spearway.com/cgi-bin/WebObjects/WODev.woa/wa/Main?
> > wikiPage=GettingFreshDataFromDatabase
> >
> > --Jonathan
> >
> >>
> >> Thanks.
> >>
> >> Jean Pierre.
> >> _______________________________________________
> >> 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.