Best Design Practice
Best Design Practice
- Subject: Best Design Practice
- From: Owen McKerrow <email@hidden>
- Date: Thu, 13 Apr 2006 09:09:35 +1000
Hi All,
Below are 2 methods that do the same thing, that is return an array
of active objects from a relationship. In this case I have a Group
which has many PostiionSets, some of which are active and some of
which are not. What Im wondering is which of the 2 methods is better
and or quicker. An is this a case by case issue or is one way
considered better/quicker than the other ?
The first method just uses the groups postionSets() array and does
the search and sort in memory. the second way uses a fetch spec and
gets the DB to do the search and sort.
/**
Return an arrray of the active postion sets of this group in sorted
order.
*/
public NSMutableArray sortedPositionsSets() throws Exception
{
//Filter the positions for just the active ones
NSMutableArray qualData = new NSMutableArray(new Integer(1));
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat("active
= %@",qualData);
NSArray activeSets = EOQualifier.filteredArrayWithQualifier
(positionSets(),qual);
return (NSMutableArray)activeSets.sortedArrayUsingComparator(new
OMGenericComparator());
}
/**
Return an arrray of the active postion sets of this group in sorted
order.
*/
public NSMutableArray sortedPositionsSets() throws Exception
{
//Filter the positions for just the active ones
NSMutableArray qualData = new NSMutableArray(new Integer(1));
qualData.addObject(this);
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat("active
= %@ AND group = %@",qualData);
EOSortOrdering order1 = new EOSortOrdering
("order",EOSortOrdering.CompareAscending);
NSMutableArray sort = new NSMutableArray(order1);
EOFetchSpecification spec = new EOFetchSpecification
("PositionSet",qualData,sort);
return editingContext().objectsWithFetchSpecification(spec);
}
I have been using the first method but after talking with a college
yesterday Im wondering if the second way may be quicker.
The in-memory will stil require a trip( or several to the DB ) to get
the position sets, and then have to do the sort in memory once they
get back. But if I have set the relationships Batch Faulting size,
would these objects not already be in memory and thus we then cut
down on the trip to the DB ?
Thoughts and comments welcome.
Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - -
"As of tomorrow, employees will only be able to access the building
using individual security cards. Pictures will be taken next
Wednesday employees will receive their cards in two weeks."
- "Dilbert Quotes" Winner, Fred Dales, Microsoft Corp
_______________________________________________
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