Re: Simple retrieval of an object by PK

From: Todd O'Bryan (toddobrya..ac.com)
Date: Thu Jul 15 2004 - 16:55:33 EDT

  • Next message: Eric Schneider: "Re: Simple retrieval of an object by PK"

    How about DataContext.registeredObject(ObjectID) ?

    It's true that you need to know the ObjectID ahead of time, but since
    the PK is usually an integer that's not meaningful, you're not likely
    to know it unless you know which object you're looking for ahead. The
    same place you'd save the PK, save the ObjectID.

    I kinda wish there were a convenience method that would return just the
    first element in a query result since I often am retrieving what I know
    are unique elements by some field which *could* be the primary key, but
    isn't.

    In that case,

    DataContext dc = //get this somewhere;
    User u = (User) ((List) dc.performQuery(User.class,
    ExpressionFactory.matchExp("login", loginID))).get(0);

    works, but is pretty verbose.

    Maybe there's an easier way I don't know about...

    Todd

    On Jul 15, 2004, at 4:17 PM, Jonathan Carlson wrote:

    > I gravitate towards powerful tools that make simple things simple and
    > hard things possible. I know that Cayenne is in this category of
    > tools, but I don't see any way to simply and quickly retrieve an
    > instance by it's primary key -- something that should be very easy and
    > concise.
    >
    > For example, when doing web apps this seems like a common use case:
    > 1) Display a list of instances that each have a link to an edit page.
    > (For example, each link would include a ?pk=999 request parameter
    > which is not visible on the HTML page.)
    > 2) When the link is clicked, the action class grabs the pk request
    > param and does a quick lookup of the obect before rendering the edit
    > page.
    >
    > There must be a straightforward simple API to get an object by its PK
    > without having to do 6 lines of code to setup a query, expression,
    > params, and execution. It's really easy to grab all instances of an
    > ObjEntity, why shouldn't it be just as easy to grab one instance?
    >
    > (BTW, I think DataContext.refetchObject(ObjectId oid) is on the right
    > track towards the simplicity I'm looking for, but that doesn't appear
    > to fill the need)
    >
    > Thanks in advance for any tips you might have in this area. It's
    > possible I just missed something, but I think I've read all the
    > relevant documentation.
    >
    > Thanks again,
    >
    > Jonathan
    >
    >
    >
    > ***********************************************************************
    > **********
    > This email and any files transmitted with it are confidential and
    > intended solely for the use of the individual or entity to whom they
    > are addressed. If you have received this email in error please notify
    > the system manager.
    >
    > Katun Corporation -- Celebrating 25 Years of Service
    > www.katun.com
    > ***********************************************************************
    > **********
    >



    This archive was generated by hypermail 2.0.0 : Thu Jul 15 2004 - 16:55:38 EDT