Re: Finally! fetch and sort w/o a display group
Re: Finally! fetch and sort w/o a display group
- Subject: Re: Finally! fetch and sort w/o a display group
- From: Nathan Dumar <email@hidden>
- Date: Wed, 23 Jun 2004 16:25:24 -0400
Art,
Remember all this stuff? If I did it the right way, I couldn't get it
to work, no matter what I tried. Now it works, just the way you had
it. Why? I could kick myself ... the MySQL adaptor was a few minor
versions old. After updating I tried this all again and it worked
without a hitch. Sorry for all the trouble.
Nathan
On Jun 4, 2004, at 4:48 PM, Art Isbell wrote:
On Jun 4, 2004, at 10:06 AM, Nathan Dumar wrote:
Here's the final form:
try {
// fetch users of this family
users = EOUtilities.objectsMatchingKeyAndValue(edCon(), "User",
"family", theFamily);
// remove master and admin users from the list
EOQualifier q =
EOQualifier.qualifierWithQualifierFormat("(usertype.userTypeNumber >
0) and (usertype.userTypeNumber < 9)", null);
users = EOQualifier.filteredArrayWithQualifier(users, q);
// sort remaining users by real name
EOSortOrdering realNameOrdering =
EOSortOrdering.sortOrderingWithKey("realName",
EOSortOrdering.CompareAscending);
NSArray nameOrdering = new NSArray(realNameOrdering);
users = EOSortOrdering.sortedArrayUsingKeyOrderArray(users,
nameOrdering);
}
I could never get objectsWithQualifierFormat to work, despite hours
of trying everything I could think of. I kept getting null pointer
exception errors ... never did figure out why, but I did get
objectsMatchingKeyAndValue to work, and did the rest with a
qualifier.
There's no reason why objectsWithQualifierFormat() shouldn't work.
The above is fetching more objects than necessary and in the process
may be increasing your app's memory usage unnecessarily. Databases
are very efficient at selecting and sorting, so you should let the
database do all of this (untested pseudocode):
// Creation of EOKeyValueQualifiers may be faster than
// EOQualifier.qualifierWithQualifierFormat() because no parsing is
involved.
EOKeyValueQualifier familyQualifier = EOKeyValueQualifier("family",
EOQualifier.QualifierOperatorEqual, theFamily);
EOKeyValueQualifier userType0Qualifier =
EOKeyValueQualifier(usertype.userTypeNumber,
EOQualifier.QualifierOperatorGreaterThan, new Integer(0));
EOKeyValueQualifier userType9Qualifier =
EOKeyValueQualifier(usertype.userTypeNumber,
EOQualifier.QualifierOperatorLessThan, new Integer(9));
EOAndQualifier q = new EOAndQualifier(new NSArray(new
EOKeyValueQualifier[] {familyQualifier, userType0Qualifier,
userType9Qualifier}));
NSArray nameOrdering = new
NSArray(EOSortOrdering.sortOrderingWithKey("realName",
EOSortOrdering.CompareAscending));
EOFetchSpecification fs = new EOFetchSpecification("User", q,
nameOrdering);
users = edCon().objectsWithFetchSpecification(fs);
Aloha,
Art
_______________________________________________
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.