On Jun 2, 2007, at 4:29 AM, Michael Gentry wrote:
Well, it would work without you providing a DataContext by creating a
default DataContext and using it (obviously, only useful if the model
is simple -- hence also needing a version where you provide the
DataContext to use).
I wouldn't even bother with a version that doesn't take a context -
IMO we should minimize the number of places in the framework that
assume a singleton Configuration based stack structure (even though
it is a default). Ideally we should get rid our code of this
assumption completely. Otherwise the usability of Cayenne across
various J2EE (and other) environments will suffer greatly.
We do have utility classes already, like DataObjectUtils (which are
mainly containers for static methods -- aka functions). This would be
a "real" class (or extension of an existing class), though.
I am with Matt on the point that any new utility should preferably
stay within the well understood framework concepts. A query that runs
itself is definitely NOT something Cayenne has ever done. I think we
can squeeze it in the current framework, tweaking what has been
already proposed - a CountQuery, by adding a new method to
DataObjectUtils: intValueForQuery (analogous to existing
"objectForQuery"). So one can do:
Query q = new CountQuery(Artist.class, qualfier);
int count = DataObjectUtils.intValueForQuery(context, q);
I'll ponder this a bit more. Doing the basic count would be pretty
easy, but getting it to work with a qualifier will be a bit more work
to make it nice.
BTW with EJBQL coming in 3.0 should provide the runtime to run the
following object syntax:
"select count(a) from Artist a where a.name = 'Dali'"
So this will provide a ready-to-use runtime for the classic count
query. Although if somebody wants to implement the count-with-
qualifier backend differently for the interim, that's fine too.
Andrus