cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Gentry" <blackn...@gmail.com>
Subject Re: performing count
Date Sat, 02 Jun 2007 01:29:08 GMT
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).

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.

As for:

   int n = Artist.numberOfRowsMatchingQuery(dc, q);

That would also be nice, although I'd not want to be forced to pass
"null" in for "q" when not needed.  Also, the query would most likely
need to be SQLTemplate-compatible, not an Expression or Query
(although maybe this can be done -- I'll have to explore).  Keep in
mind this is going outside of the ORM arena to a degree.  A row count
isn't being mapped to Java classes with relationships/attributes/etc.
You can't persist it back to the DB.  :-)

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.

Thanks,

/dev/mrg


On 6/1/07, Matt Kerr <mr_matt_kerr@mac.com> wrote:
> Here's some random feedback ..
>
> I have the need for row counting here and there, so having support in cayenne would be
great.
>
> Couple things ..
>
> >int rowCount = new CountQuery(Artist.class).getCount();
>
> I don't see how this works without a DC - ?
> (Maybe I'm just missing something obvious ..)
>
>
> And, for me personally, ..
> The notion of "utility" means 'weakly understood' .. so, I try and avoid anything for
the 'utility' junk box as much as humanly possible.  If it's real, and ligit, I try like heck
to find a real home (abstraction) where it would reside.
>
> Also another personal preference .. I dislike the vague names 'getCount' :-/
>
> If I was reading someone else's  code, I wouldn't mind seeing something like:
>
>     int n = Artist.numberOfRowsMatchingQuery(dc, q);
>
> where q==null counts all.  I think from the OO side of things (which is the whole point
of ER -> OO), that's really what you're after.
>
> I'd rather make the ~base class support rich - than spread stuff into 'utility' classes
here and there.
>
> Food for thought.  Dunno if it's even plausible.
>
> 2cents.
> Thanks,
> -Matt
>
>
>
> On Friday, June 01, 2007, at 11:45AM, "Michael Gentry" <blacknext@gmail.com> wrote:
> >Looking at that CountQuery class makes me think we should actually add it to
> >Cayenne as a utility class.  Perhaps with two additional methods added:
> >
> >public int getCount();
> >public int getCount(DataContext dc);
> >
> >
> >That way you could then do:
> >
> >CountQuery query = new CountQuery(Artist.class);
> >int rowCount = query.getCount();
> >
> >or even:
> >
> >int rowCount = new CountQuery(Artist.class).getCount();
> >
> >I think that would simplify things and needing a count is a pretty comment
> >activity.  Perhaps for more flexibility, it would be good to have a
> >constructor that could take a WHERE clause, too, in case you only need
> >counts matching certain criteria.
> >
> >Thoughts?
> >
> >/dev/mrg
> >
>

Mime
View raw message