Re: Convenience functions in model classes
Re: Convenience functions in model classes
- Subject: Re: Convenience functions in model classes
- From: Chuck Hill <email@hidden>
- Date: Mon, 14 Apr 2008 11:30:31 -0700
On Apr 11, 2008, at 8:50 PM, Jeff Schmitz wrote:
That seems like an exceedingly odd way to get a single entry on a
single Pool. Does the code that calls this not know the Pool? How
does it get the Pool and Entry names?
Yes, it will only have the Strings (you gotta start somewhere).
Even if you only have the names,
EOQualifier entryQual = ERXQ.and(Entry.NAME.eq(entryName),
ERXQ.equals(ERXQ.keyPath(Entry.POOLKEY, Pool.NAMEKEY), poolName));
Will the fact that entryName is not globally unique (it's only
unique within a pool) have any affect on the speed of the fetch?
There will be a LOT of entries, and not near as many pools. While I
have no idea how the above query will ultimately run, I would think
finding the pool first, and then just searching for the entry name
from within just that pool would be the most efficient way.
No, that will be slower. You will be doing two fetches, where one
would do. Indexes (you will need to add them manually) will keep the
queries fast.
If you want to have any concerns about optimization and WO, you really
need to get familiar with SQL optimization for relational databases.
Entry entry = Entry.fetchRequiredEntry(ec, entryQual);
Seems like a more direct way to do it.
Cool. I didn't even know about ERXQ (Webobjects and Wonder are
LARGE APIs, I'm only beginning to learn Wonder.
Yeah, well, good luck with that. Mike can type faster than you you
can learn. :-P
And it handles the exception for you so no need for a try ... catch.
But, fetRequiredEntry can still throw the exception, right?
Yes, but you don't have to do it manually. It will be a different
exception, EOObjectNotAvailable.
NOTE: I don't use the key stuff from Wonder yet, so I am just
guessing at Entry.POOLKEY for the name of the property.
Close, it's POOL_KEY.
// Check first round to see if any actuals have been set.
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++) {
// This call is to the Mike Schrag approved "game"
function from
// my previous message (see below).
if (entry.game(i, j).selectedItem() != 2) {
// If selectedItem isn't 2 for any game, results have been
posted.
results = true;
//Break out of loops
i = 4;
j = 7;
}
}
}
How about
boolean posted = false;
// Check first round to see if any actuals have been set.
for (int i = 0; i < 4 && ! posted; i++) {
for (int j = 0; j < 7 ! posted; j++) {
// This call is to the Mike Schrag approved "game"
function from
// my previous message (see below).
if (entry.game(i, j).selectedItem() != 2) {
// If selectedItem isn't 2 for any game, results have been
posted.
posted = true;
}
}
}
No nasty hacking of for loop variables.
Yeah, I figured I might get hammered on that, but was too lazy to
improve it at the time.
:-P
As always, THANKS! Better to find out the right way to do things
now, before getting too far down the line.
Onward and upward!
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
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