Re: Retrieving by a property in a toMany relation

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Oct 13 2005 - 10:49:40 EDT

  • Next message: Oscar Picasso: "Re: Retrieving by a property in a toMany relation"

    Query will generally be slower than almost any in-memory search.

    You map approach would work ... just override the generated methods
    that you've mentioned. But there is an indexing step involved
    (originally when creating a Map, you have to walk through the list to
    put the objects in the map), it may not be always faster than your
    last approach with direct search.

    Your last approach, while slower than the map approach on the
    surface, is probably the best. It is simple and very reasonable. Like
    I said, depending on your usage it may even turn out faster than the
    map.

    Andrus

    On Oct 13, 2005, at 9:42 AM, Oscar Picasso wrote:

    > Hi,
    >
    > Many times I need to retrieve a particular object which is on the
    > "many" end of
    > a relation, using one of its properties.
    >
    > Example:
    > Artist -toMany- Panting
    >
    > I want something like that:
    > someArtist.paintingByName("A painting name");
    >
    > What would be the best way to deal with this kind use case, in
    > terms of memory,
    > speed, simplicity, thread safety?
    >
    > I have thought of various approaches:
    > - using a query. Only retrieves persisted objects if I remember.
    > - a HashMap and overriding the relevant setXXX, getXXX, addToXXX,
    > removeFromXXX
    > ... so as to update the Map. This one seems to me cumbersome as
    > there many
    > methods that could be involved. It would be more feasible if I knew
    > for sure
    > that a very limited number of methods are always involved when
    > updating a
    > relation.
    > - walking through the List associated to the relation and returns
    > the object
    > that matches the property. This one seems very inefficient.
    >
    > Any other idea?
    >
    >
    > Thanks
    >
    >
    > Oscar



    This archive was generated by hypermail 2.0.0 : Thu Oct 13 2005 - 10:49:45 EDT