The reason I'm using an SQLTemplate/count(*) is because I have a summary
page with about 25 rows (each row a summary of different data) which
displays the record count. You can click on the row you want details on
and that's when I fetch the real rows. I don't want to fetch the detail
data for the other rows unless/until I need them. If I needed the data
and also wanted to display the number of rows, I wouldn't have used an
SQLTemplate -- I'd just fetch the rows and could ask for the size() and
also have the data.
It all depends on your application and what you are trying to do. I was
trying to make mine run faster (at least at the summary level) and be
more memory efficient.
/dev/mrg
-----Original Message-----
From: Gili [mailto:cowwo..bs.darktech.org]
Sent: Tuesday, September 20, 2005 11:25 AM
To: cayenne-use..bjectstyle.org
Subject: Re: How to do these two tasks properly in cayenne?
I think this is what I was thinking of:
http://www.objectstyle.org/cayenne/userguide/introduction/whats-new.html
"Lazy Relationship Creation". Looks like it doesn't explicitly mention
the list size.
Looking at the implementation of ToManyList.size(), it is
currently
defined as "return resolvedObjectList().size()" but we could easily
redefine it as "If the list is not yet resolved, issue a count(*) query,
otherwise use the original implementation."
It's also a matter of optimization. If the user almost always
uses a
list after retrieving its size, then the current implementation is
preferable. If otherwise, the new implementation is preferable. I'm
guessing we have no statistics on this?
Gili
Gentry, Michael (Contractor) wrote:
> I use an SQLTemplate to retrieve sizes. I'm 99% certain Cayenne would
> have to fetch all rows to give you the size using a regular
SelectQuery.
>
> For Sybase (you'll have to tailor it for MySQL, probably), I used
> something like:
>
> final String queryString = "SELECT count(*) 'rowCount' from Foo where
> bar = $bar";
> final SQLTemplate queryTemplate = new SQLTemplate(Foo.class,
> queryString, true);
>
> queryTemplate.setFetchingDataRows(true);
>
> Map queryParameters = new HashMap(1);
> queryParameters.put("bar", "xyzzy");
> SQLTemplate query =
queryTemplate.queryWithParameters(queryParameters);
> List results = dataContext.performQuery(query);
>
> if (results.size() == 1)
> return results.get(0).get("rowCount").intValue();
> else
> return 0;
>
>
> -----Original Message-----
> From: Gili [mailto:cowwo..bs.darktech.org]
> Sent: Tuesday, September 20, 2005 10:49 AM
> To: cayenne-use..bjectstyle.org
> Subject: Re: How to do these two tasks properly in cayenne?
>
>
>
> For #1, I believe it is possible to create a SelectQuery for the
> table
> in question, and invoke size() on the resulting size(). My guess is
that
>
> Cayenne will be smart enough to invoke "select count(*)" without
> actually retrieving the actual rows.
>
> Gili
>
> Tore Halset wrote:
>
>>On Sep 20, 2005, at 9:26, Tomas Jucius wrote:
>>
>>
>>>I wanted to know how properly to do these:
>>>
>>>1) count rows in the table
>>>2) execute "password" function and get result..
>>>
>>>DataBase: MySql..
>>>
>>>Is it possible with cayenne to execute simple query and get result
>
> map?
>
>>
>>Yes, using SQLTemplate
>>
>>http://www.objectstyle.org/cayenne/userguide/fetch/sqltemplate.html
>>
>> - Tore.
>>
>
>
-- http://www.desktopbeautifier.com/
This archive was generated by hypermail 2.0.0 : Tue Sep 20 2005 - 11:34:46 EDT