Re: Mapping SQL query results to a Entity Object

From: John Martyniak (jmarty..x.netcom.com)
Date: Wed Mar 02 2005 - 18:29:33 EST

  • Next message: Michael Mangus: "Re: Help with Cayenne Deployment?"

    Thanks for the info.

    I kind of thought that is how it would have to be done.

    But I thought that it would be cool to have a application based view of the
    data. Kind of a way to get around not having views in mysql. But it would
    be more useful because you wouldn't have to involve the DBAs to make a
    change. The other advantage would be to create a manipulated view of data.

    -John

    On 3/2/05 5:55 PM, "Gentry, Michael (Contractor)"
    <michael_gentr..anniemae.com> wrote:

    > I'm probably about to give some of my patented bad advice, but ...
    >
    > Does a map count as an object you can use? If so, I use something
    > similar to get counts:
    >
    > // Adjust SELECT as needed
    > final String queryString = "SELECT count(t0.createDate) 'rowCount' FROM
    > ....";
    > final SQLTemplate queryTemplate = new SQLTemplate(AnEntity.class,
    > queryString, true);
    > queryTemplate.setFetchingDataRows(true);
    > List results = dataContext.performQuery(queryTemplate);
    >
    > A note about the "AnEntity.class" portion. Even though you won't be
    > pulling back a List of AnEntity objects (you get a List of Maps), you
    > have to specify that so Cayenne knows which DataNode to use (which makes
    > more sense if you have multiple DataNodes). So just plug in an entity
    > that makes sense for you there.
    >
    > Once you have your results, just iterate over them and ask the map for
    > the values by name (use "rowCount" -- or "counts" or whatever you call
    > it -- for your count() portion).
    >
    > True, it's not an ObjEntity, but still useful for getting reporting
    > data. Keep in mind you can't update the values and automatically push
    > it back to the database with a commitChanges().
    >
    > /dev/mrg
    >
    >
    > -----Original Message-----
    > From: John Martyniak [mailto:jmarty..x.netcom.com]
    > Sent: Wednesday, March 02, 2005 5:39 PM
    > To: Cayenne User
    > Subject: Mapping SQL query results to a Entity Object
    >
    >
    > I would like to find out if it is possible to map the results of a query
    > to
    > an entity object that doesn't map to a db table.
    >
    > For example:
    >
    > I have a query something like:
    > Select username, count(*) counts from users group by username order by
    > counts desc limit 5;
    >
    > I would like this to show up in a object that I can then use.
    >
    > Is this even possible?
    >
    > Or does a obj entity have to map to a db entity? If you go through
    > modeler
    > it certainly seems like it needs to.
    >
    > Any thoughts or suggestions would be very helpful.
    >
    > -john
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Mar 02 2005 - 18:29:37 EST