You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by John McNally <jm...@collab.net> on 2001/10/22 20:49:15 UTC

Re: Getting row counts using Criteria

Here is a code exerpt from scarab, the DISTINCT part may or may not work
in turbine2.x, count(*) should work as well as specifying a column.

        Criteria crit = new Criteria();
        crit.addSelectColumn("count(DISTINCT a1." + ACT_ISSUE_ID + ')');
        addMoreCriterionTo(crit);

        List records = ActivityPeer.doSelectVillageRecords(crit);
        return ((Record)records.get(0)).getValue(1).asInt();


"Colquhoun, Adrian" wrote:
> 
> Hi,
> 
> I would like to add some methods to my database peer classes to return row
> counts. I have written code like
> 
> e.g. in EventPeer for a table called Event
> 
>         int getRowCount(Criteria c){
> 
>                 try{
>                         Vector v = BaseEventPeer.doSelect(c);
>                             return v.size();
>                         }
>                         catch(Exception e){
>                         return 0;
>                         }
>         }
> 
> Presumably this will retrieve all the data from the database for my query ?
> (potentially a large amount of data that I don't actually want) - is there a
> better way ?
> 
> Thanks
> 
> Adrian
> 
> 
> 
> =======================================================================
> Information in this email and any attachments are confidential, and may
> not be copied or used by anyone other than the addressee, nor disclosed
> to any third party without our permission.  There is no intention to
> create any legally binding contract or other commitment through the use
> of this email.
> 
> Experian Limited (registration number 653331).
> Registered office: Talbot House, Talbot Street, Nottingham NG1 5HF
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org