Re: questions

From: Eric Polino (aluin..mail.com)
Date: Wed Feb 13 2008 - 14:35:16 EST

  • Next message: Eric Polino: "Re: questions"

    On Feb 13, 2008 2:26 PM, Kevin Menard <kmenar..ervprise.com> wrote:
    > On 2/13/08 2:04 PM, "Eric Polino" <aluin..mail.com> wrote:
    >
    >
    > >>> 2. I've read in many places how Cayenne deals with joins for you, but
    > >>> nowhere do I see an example of how its done. Here's an example
    > >>> problem I'm dealing with.
    > >>>
    > >>> Schema:
    > >>>
    > >>> Reservation (n to 1) Site
    > >>> Site (n to 1)
    > >>> Site contains a type field
    > >>>
    > >>> I want to get all the Reservations of a given for a given type of
    > >>> site. In sql I would execute something like, "select * from
    > >>> Reservation, Site, SiteType where SiteType.Name='Something' and
    > >>> Site.typeID = SiteType.id and Reservation.siteID = Site.id"
    > >>>
    > >>> Short of writing an parameterized sql string and executing that in my
    > >>> code, how do I do that with Cayenne? I hope I explained all that well
    > >>> enough...make sense?
    > >>
    > >> Just map the relationships in the modeler. Cayenne takes care of the SQL
    > >> for you. The following guide should help you get started with the modeler:
    > >>
    > >> http://cayenne.apache.org/doc20/tutorial-starting-mapping-project.html
    > >
    > > I've been using the modeler and the relationships are setup, I just
    > > don't know how to do queries based on those relationship...ie the one
    > > mentioned above
    >
    > Sorry. I glossed over the original question.
    >
    > You want to use a qualifier expression:
    >
    > http://cayenne.apache.org/doc/qualifier-expressions.html
    >
    > Expression factory is the easiest way to do this:
    >
    > http://cayenne.apache.org/doc/api/org/apache/cayenne/exp/ExpressionFactory.h
    > tml
    >
    > So, you may have something like:
    >
    > Query q = new SelectQuery(Site.class,
    > ExpressionFactory.matchDbExp(Site.NAME, "Something");
    >
    > List<Site> sites = context.performQuery(q);
    >
    > for (Site s :sites)
    > {
    > System.out.println(s.getReservation().toString();
    > }
    >

    I've been doing stuff like this already, that is simple. I'm talking
    about doing stuff like...

    Query q = new SelectQuery(Reservation.class,
    ExpressionFactory(SiteType.NAME, "Something"));
    List<Reservation> res = ...

    This would select all the Reservations to a Site of SiteType "Something".

    > You'll have to make substitutions as appropriate for your actual code.
    >
    > --
    > Kevin
    >
    >

    -- 
    "None are more hopelessly enslaved than those who falsely believe they
    are free."
                                          --Goethe
    

    "Freedom is living without government coercion." --Ron Paul (www.ronpaul2008.com)



    This archive was generated by hypermail 2.0.0 : Wed Feb 13 2008 - 14:35:53 EST