Re: table row count in cayenne

From: Marek Wawrzyczny (marek_wawrzyczn..nternode.on.net)
Date: Fri Jul 28 2006 - 02:59:30 EDT

  • Next message: Rashid Khan: "Re: table row count in cayenne"

    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



    This archive was generated by hypermail 2.0.0 : Fri Jul 28 2006 - 05:13:39 EDT