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: Art Isbell <email@hidden>
- Date: Fri, 4 Jun 2004 10:48:28 -1000
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.