Re: Proposed change

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Oct 02 2004 - 20:17:55 EDT

  • Next message: Andrus Adamchik: "Re: Proposed change"

    Hi Cris,

    I think there is some misunderstanding. Lets first make sure that you
    are not overcomplicating things. I'll go over your examples, with
    solutions that I would use based on current Cayenne features. Please
    tell me if I am wrong and you need something else.

    > DataObject[] criteria = {monet, louvre};
    > List paintingList =
    > DataObjectUtils.objectsByForeignKeys(context, Painting.class,
    > criteria);

    // create qualifier like that, or use ExpressionFactory instead of
    "fromString" below
    Expression qualifier = Expression.fromString("toArtist = $artist and
    toGallery = $gallery");

    // bind variables
    ...

    // run query
    List paintingList = context.performQuery(new
    SelectQuery(Painting.class, qualifier));

    No need for SQLTemplate or DB expressions, just use relationships and
    query API.

    > I'd also propose (but have not yet taken a stab at implementing)
    > having multiple overloaded methods for each getArray() method.
    > Something like this might work:
    >
    > List paintingList = monet.getPaintingArray(louvre); // or
    > List paintingList = louvre.getPaintingArray(monet);

    As class generation is template-based, I guess custom templates are the
    way to go. We just need to make sure that Velocity context used for
    template processing has all the stuff to infer these methods. But in
    any case there is a caveat - a List returned by
    "monet.getPaintingArray()" is a "real" relationship (in that you can
    modify it by adding/removing objects and it will be reflected in DB),
    while "monet.getPaintingArray(louvre)" will be just a List with no
    special persistence properties. So IMO just using a simple query is
    much easier.

    > RecordType recType = ctx.performQuery(...);
    >
    > Map key = new HashMap();
    > key.set("language_code", "en");
    > key.set("record_type", DataObjectUtils.intPKForObject(recType));
    >
    > RecordTypeLanguage recTypeLang =
    > (RecordTypeLanguage)ctx.registeredObject(new
    > ObjectId(RecordTypeLanguage.class, key));
    >
    > This is a waste. It seems to me that a better solution would be a
    > designation of part of a compound key as meaningful in the modeler,

    But you can do that! In the Modeler manually create an ObjAttribute for
    RecordTypeLanguage "language_code" PK DbAttribute - Cayenne doesn't
    create it by default, but nothing should prevent you from doing it
    yourself. And you can fetch RecordTypeLanguage via a query (as shown in
    the first example above), instead of using the relationship.

    I hope this solves the problems that you had.

    Cheers
    Andrus



    This archive was generated by hypermail 2.0.0 : Sat Oct 02 2004 - 20:18:02 EDT