Re: aggregate queries

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Jun 11 2004 - 15:17:01 EDT

  • Next message: Andrus Adamchik: "Re: cannot load jdbc driver named 'org.gjt.mm.mysqlDriver'"

    Hi Dan,

    The most straightforward option is using SQLTemplate:

    http://objectstyle.org/cayenne/userguide/fetch/sqltemplate.html
    http://objectstyle.org/cayenne/userguide/fetch/sqltemplate-
    scripting.html

    Also you will likely need to call "setFetchingDataRows(true)" on
    SQLTemplate query before executing it.

    BTW, the upcoming 1.1M7 release will support SQLTemplate creation via
    Modeler (with SQL dialect customization by DB!). This should simplify
    its use immensely.

    Andrus

    On Jun 11, 2004, at 1:13 PM, dan17..elus.net wrote:
    > I'm using Cayenne in my application and I need to do an aggregate
    > query on my
    > database. For example, I need a query to do this:
    >
    > select b.year, b.month, sum(b.value1), sum(b.value2)
    > from entity a, entity_data b
    > where (a.entity_id = b.entity_id) and (a.entity_group_id = 1234)
    > group by b.year, b.month
    >
    > entity, and entity_data both map to cayenne objects. I could fetch
    > all the
    > objects from entity_data and then add them up, but that puts the work
    > on the
    > object layer and takes too long.
    >
    > How do I make Cayenne do something similar, but keep the processing in
    > the
    > database layer for speed?
    >
    > - Dan



    This archive was generated by hypermail 2.0.0 : Fri Jun 11 2004 - 15:17:04 EDT