Re: sort attribute for referenced relation

From: Andrus (andru..bjectstyle.org)
Date: Thu Nov 14 2002 - 23:10:15 EST

  • Next message: Dirk Olmes: "Re: sort attribute for referenced relation"

    At 04:47 AM 11/15/2002 +0100, Dirk Olmes wrote:
    >Andrus Adamchik wrote:
    >>Hi Martin,
    >>this feature is not there yet. In fact one of our contributors, Holger,
    >>is currently working on it.

    [...]

    >Having sorted relationships that will stay sorted even after you add some
    >objects to it is not a trivial task. The problem lies in the Java APIs:
    >
    >The return type for relationships in cayenne is List. However, the
    >documentation for List states: "The user of this interface has precise
    >control over where in the list each element is inserted."

    See below...

    >Cayenne uses org.objectstyle.cayenne.access.ToManyList for relationships.
    >Without looking at the source I'd guess that is so because then you'll be
    >able to map adds to the List to inserts to the database.

    Custom implementation was mostly due to the fact that we wanted lazy
    resolution of to many relationships. Anyway, a few ideas though.

    1. An "executive" way.

    As of now users shouldn't add objects to the list directly. The right way
    is to use methods in DataObjects like "addToRelname(Someclass obj)" and
    "removeFromRelname(Someclass obj)" (kind of like
    "addObjectToBothSidesOfRelationshipWithKey" in EOF).

    Now, Java has a notion of "unmodifiable" lists (via java.util.Collections
    wrappers), though this is dumb and not obvious from the interface. So we
    can take advantage of that and make sure that relationship list is
    "unmodifiable", and safely implement the sorting.

    2. Now that I wrote (1), I almost regret about it :-). Your idea of
    modifying to-many relationships via simple "add/remove" list API is very
    appealing... So, why don't we concentrate on making add/remove work via
    ToManyList (clean behind the scenes way). Sorting will be done initially on
    fetch (configurable from the DataMap and Modeler). And if we follow your
    logic, a user should be in full control of the list. So once she
    inserts/removes something, she shouldn't expect it to be ordered (since she
    just modified it). Instead she could use Collections API to order it any
    way she wants.

    I think (2) is very reasonable and adds lots of value to Cayenne beyond
    just ordering. Though it requires more work.

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Nov 14 2002 - 23:09:33 EST