Re: Retrieving by a property in a toMany relation

From: Cris Daniluk (cris.danilu..mail.com)
Date: Fri Oct 14 2005 - 09:42:52 EDT

  • Next message: Andrus Adamchik: "Re: double inner join"

    Just make sure you prefetch on any properties where you'll be doing
    this and you shouldn't have a problem.

    On 10/13/05, Oscar Picasso <oscgoogl..ahoo.com> wrote:
    > Thank you for your input. I actually started using the last approach.
    >
    > So I will stick with it unless I experience some performance issues.
    >
    > --- Andrus Adamchik <andru..bjectstyle.org> wrote:
    >
    > > 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
    > >
    >
    >
    > __________________________________________________
    > Do You Yahoo!?
    > Tired of spam? Yahoo! Mail has the best spam protection around
    > http://mail.yahoo.com
    >



    This archive was generated by hypermail 2.0.0 : Fri Oct 14 2005 - 09:42:54 EDT