Re: Random selection

From: Mike Kienenberger (mkienen..laska.net)
Date: Sat Dec 20 2003 - 11:07:54 EST

  • Next message: Andrus Adamchik: "Re: Random selection"

    Jim Menard <jim..o.com> wrote:
    > 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.

    Ah, I didn't notice that was the problem.

    Hmm.

    I don't know if page sizes can be mixed with prefetches, so you'll have to
    wait to hear from someone more knowledgeable on that.

    I can help you by starting with the primary key. I think there's a couple
    of ways to do this. However, I use this generic method (inherited from the
    superclass from all of my DataObjects).

            public Number primaryKey()
            {
                    String primaryKeysString = null;
                    Map pkAttributes = this.getObjectId().getIdSnapshot();
                    if (1 != pkAttributes.size()) throw new
    CayenneRuntimeException("multi-field primary key found.");
                    
                    Iterator pkIterator = pkAttributes.keySet().iterator();
                    String primaryKeyName = (String) pkIterator.next();
                    Number primaryKeyValue = (Number)pkAttributes.get(primaryKeyName);
                    
                    return primaryKeyValue;
            }

    You might also define a reverse to-one relationship from photo to album,
    then do a

    matchExp("photo.album", theAlbum)

    in which case you probably wouldn't need the primary key.

    -Mike



    This archive was generated by hypermail 2.0.0 : Sat Dec 20 2003 - 11:08:27 EST