cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marek Wawrzyczny <marek_wawrzyc...@internode.on.net>
Subject Re: table row count in cayenne
Date Fri, 28 Jul 2006 06:59:30 GMT
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

Mime
View raw message