Re: Child EditingContext and fetches
Re: Child EditingContext and fetches
- Subject: Re: Child EditingContext and fetches
- From: Lachlan Deck <email@hidden>
- Date: Thu, 23 Mar 2006 10:22:11 +1100
Hi there,
On 22/03/2006, at 10:44 PM, Fabrice Pipart wrote:
On Mar 22, 2006, at 12:21 AM, Lachlan Deck wrote:
EOEditingContext childEc;
NSMutableSet days;
EOFetchSpecification fs;
EOQualifier qual; // assume exists
childEc = new EOEditingContext(session().defaultEditingContext());
days = new NSMutableSet();
Do you mean I can keep a reference on those "Day" objects?
I am already doing it, OK.
Yes. If they're not saved to the database as yet you ought to keep a
reference to it somewhere if you need to use it again.
days.addObject(EOUtilities.createAndInsertInstance(childEc, "Day"));
fs = new EOFetchSpecification("Day", qual, null);
days.addObjectsFromArray(childEc.objectsWithFetchSpecification(fs));
If I don't misundertand,
childEc.objectsWithFetchSpecification(fs)
should return null since there is no difference with what I
proposed...
Rather if there's no data as yet in the database it should return an
array of count == 0; otherwise, it will indeed return an array of
objects with the count equal to the Days that satisfied the given
qualifier.
try {
childEc.saveChanges();
parentEc.saveChanges();
} catch(...) {
}
Is there a way to fetch those objects anyway? or I should just
keep an array of them and look for the EO I am looking for in a
"for" loop ?
To find the object you're looking for you have the option of using
an in-memory EOQualifier operation. e.g.,
EOQualifier.filteredArrayFromQualifier(days.allObjects(), qual);
YES !
I knew it existed but forgot that... that was what I was looking for !
Great. The best way to find this stuff in the future is to look at
the api for the classes you're using for the fetch. Starting with
EOFetchSpecification which takes various arguments in the constructor
including EOQualifier you can say, hmm what can that do?.... etc.
Before long you'll find the stuff you need. The api is often very
helpful in that regard.
It will allow me to use the qualifiers I have and work in memory
since I cannot work in database :-)
You can use the qualifiers for both, which makes them very useful.
I suppose that in term of performance, it is faster than a for loop.
That'll depend on a few factors but for now they're certainly
convenient. I'd worry about speed for things that are noticeably
slow. Until then do what's convenient.
with regards,
--
Lachlan Deck
_______________________________________________
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