Re: Random selection

From: Jim Menard (jim..o.com)
Date: Sat Dec 20 2003 - 10:42:13 EST

  • Next message: Mike Kienenberger: "Re: Random selection"

    Mike,

    On Dec 20, 2003, at 9:55 AM, Mike Kienenberger wrote:

    > Jim Menard <jim..o.com> wrote:
    >> I have an album of photos, and I want to select a random photo to
    >> display. I figured I could use setFetchingDataRows, select the entire
    >> list of photos, then randomly select one and call objectFromDataRow to
    >> "flesh out" the photo.
    >>
    >> Cayenne normally performs magic to retrieve the list of photos. How do
    >> I do it myself? Alternately, how can I tell the album to use
    >> setFetchingDataRows when it selects the list of photos?
    >>
    >> Finally, is this an unnecessary optimization? Should I not worry about
    >> reading all of the photos into memory and just call album.getPhotos()?
    >
    > Have you looked at using Paginated Queries instead?
    >
    > You could just set the page size to 1, and read in objects as regular
    > DataObjects rather than DataRows.
    >
    > http://www.objectstyle.org/cayenne/userguide/perform/paged-queries.html

    I understand how that would help, but I still need to either write the
    query to retrieve the photos from the album (the original "????" point
    in my code) or somehow tell the album to use setPageSize() before
    calling getPhotos().

    I can't figure out how to perform the simplest of queries---retrieving
    all of the photos owned by the album---without explicitly grabbing the
    album's primary key and using it. Is that what I have to do? If so, I
    need help. I can't find the CayenneDataObject or DataContext code that
    will help me do that.

    Jim

    -- 
    Jim Menard, jim..o.com, http://www.io.com/~jimm/
    [On the Apple supercomputer at Virginia Tech] "Besides if an AI 
    manifests
    itself it'd be less likely to destroy the world and more likely to tell 
    you
    that your white socks do not match your purple tie." -- Epistax on 
    Slashdot
    



    This archive was generated by hypermail 2.0.0 : Sat Dec 20 2003 - 10:42:19 EST