Re: Using EO
Re: Using EO
- Subject: Re: Using EO
- From: Jonathan Miller <email@hidden>
- Date: Wed, 25 May 2005 08:39:06 -1000
Thanks Jerry-
That's the kind of kick in the pants I needed to not get lazy and do
it the comfortable way.
Regards
Jon
On May 25, 2005, at 3:27 AM, Jerry W. Walker wrote:
Though I don't disagree with specific point made in this thread, I
hate the direction that it has taken.
If this is your first WO project, then there are a few reasons to
do this without using raw SQL. Probably the first, and foremost, is
to get used to doing things with objects rather than with tables.
My first concern is the statement of the original question:
"is there a way to build a FetchSpecification that would
accomplish the sql equivalent of "SELECT SUM(COLUMN_NAME) FROM
TABLE_NAME"
This question is clearly framed from the perspective of "I have a
table of rows with which I want to do something, now how do I get
WO to help me do that thing to my table in the same way I've always
done these things with SQL?"
Experienced WO developers would think instead of the object graph
that we are manipulating in our object oriented java application
rather than the rows we have stored in our relational database.
Rephrasing the question, "I have a set of objects 'O' with an
attribute 'a'. How do I obtain the sum of that attribute across
those objects?"
The obvious first answer is Sacha's first answer:
"My preferred method is to use the NSArray @sum key value coding
(note: no need to do an enumeration). "
Perhaps those objects have already been cached and we don't need to
fetch raw rows. Perhaps the sum could be obtained as a side effect
of another necessary operation on those objects later when they
have already been fetched.
Failing either of those two possibilities, I would still first
write the fetch without referencing raw rows and get it to work.
Finally, if the result is clearly taking too long, I would profile
where the delays are occurring and, if in database fetches, then
would start to consider raw rows. The point being that referencing
raw rows is a last resort rather than a way to move into the
comfort zone of old habits with result sets.
So what are the down sides to just moving immediately to raw rows?
* a missed opportunitiy to get used to the WO way
* the short circuiting of several elegant features built into WO
to help one deal with objects rather than rows
* the higher probability of weak object oriented design built up
from this raw row decision
I'm sure others could add more with a little more thought, but I
have to catch a train.
Good luck with WebObjects and welcome to the fold.
Best regards,
Jerry
On May 25, 2005, at 3:37 AM, Sacha Mallais wrote:
On May 25, 2005, at 12:15 am, Jonathan Miller wrote:
Hmm... I guess my only question is which way has the best
performance. To answer my own question I would assume it to by
passing raw SQL. This is my first web site with WO and I was
hoping I could avoid doing that however(it's just too cool not to
have to use SQL).
My preferred method is to use the NSArray @sum key value coding
(note: no need to do an enumeration). However, if you have many
many values to aggregate, then you're best bet is indeed raw SQL.
sacha
On May 24, 2005, at 5:19 PM, Sacha Mallais wrote:
On May 24, 2005, at 8:00 pm, Jonathan Miller wrote:
is there a way to build a FetchSpecification that would
accomplish the sql equivalent of "SELECT SUM(COLUMN_NAME) FROM
TABLE_NAME"
I know you can select the objects and then add them using a
java enumeration but I was wondering if there is another way.
The most obvious is to construct the SQL yourself and send it
directly using the low-level EOF stuff (or even the JDBC
stuff...). I mention it because, as WO developers, we sometimes
forget that there's SQL back there ;-)
A more interesting (if not hackish...) way to accomplish this
would be to create a new entity with the same table name and a
single derived attribute of "sum(column_name)". You can then
either generate a full Java class for that or just use raw rows.
Also, the PracticalWO frameworks (and the GVC frameworks -- also
to be released soon, and, come to think about it, probably the
ProjectWOnder frameworks too...) have a helper method that makes
aggregate queries more simple.
HTH,
sacha
-- Sacha Michel Mallais - 400 lb. chimp
Global Village Consulting Inc.: http://www.global-village.net/
1. Never tell everything at once.
-- Ken Venturi, Ken Venturi's Two Great Rules of Life
-- Sacha Michel Mallais
President / Developer Extraodinaire
Global Village Consulting Inc. http://www.global-village.net/
The bird of paradise alights only upon the hand that does not grasp.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40codefab.com
This email sent to email@hidden
--
__ Jerry W. Walker, Partner
C o d e F a b, LLC - "High Performance Industrial Strength
Internet Enabled Systems"
email@hidden
212 465 8484 X-102 office
212 465 9178 fax
_______________________________________________
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