You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Rashid Khan <ra...@gmail.com> on 2006/07/28 08:44:43 UTC

table row count in cayenne

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

RE: table row count in cayenne

Posted by "McDaniel, Joe R." <jo...@ngc.com>.
Some databases allow embedded queries so that one can get the count
simply (and efficiently?) by doing 
	
	SELECT COUNT(*) FROM (the real select goes here);

This works in Oracle but ....

Joe 

RE: table row count in cayenne

Posted by "Gentry, Michael (Contractor)" <mi...@fanniemae.com>.
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:rashidk3@gmail.com] 
Sent: Friday, July 28, 2006 8:34 AM
To: cayenne-user@incubator.apache.org
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 <ma...@internode.on.net> 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
>

Re: table row count in cayenne

Posted by Rashid Khan <ra...@gmail.com>.
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 <ma...@internode.on.net> 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
>

Re: table row count in cayenne

Posted by Marek Wawrzyczny <ma...@internode.on.net>.
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