You could include the CountQuery class in your project: http://cwiki.apache.org/confluence/display/CAYDOC/Customizing+Queries
I thought there was another, perhaps simpler, way of doing it, but it is too early in the morning for me to recall right now. /dev/mrg -----Original Message----- From: Rashid Khan [mailto:[EMAIL PROTECTED] Sent: Friday, July 28, 2006 8:34 AM To: [email protected] Subject: Re: table row count in cayenne Thanks Marek for your suggestion. I would still like to ask whether there are any other efficient ways to know the count of rows in a table in cayenne. Any ideas? Thanks, Rashid Khan On 7/28/06, Marek Wawrzyczny <[EMAIL PROTECTED]> wrote: > Hi Rashid, > > The answer is yes... and I believe that the following code achieves that on > both single and multi tier approaches (well it works on multi-tier client > code): > > String entity = getContext().getEntityResolver().lookupObjEntity( > persistentClass).getName(); > HashMap map = new HashMap(); > map.put("entityName", entity); > addWhereClause(map); > NamedQuery query = new NamedQuery("EntityCount", map); > Map row = (Map) getContext().performQuery(query).get(0); > return ((Number) row.get("C")).intValue(); > > Then, in the modeller create the following Query, in this case it is > called "EntityCount": > > SELECT #result('count(*)' 'int' 'C') FROM $entityName $whereClause > > Hope that helps, > > Marek Wawrzyczny > > > On Friday 28 July 2006 16:44, Rashid Khan wrote: > > Hello there, > > > > I want to know what is the most efficient way in cayenne to find out > > how many rows I have in a table. > > > > Do I have to use something equivalent to the SQL statement: "SELECT > > COUNT(*) FROM tablename"? > > > > Thanks, > > > > Rashid Khan >
