Re: getting a List of Comparables, feature request?

From: Todd O'Bryan (toddobrya..ac.com)
Date: Mon Mar 14 2005 - 05:28:41 EST

  • Next message: Tore Halset: "Re: getting a List of Comparables, feature request?"

    OK. Now I just have to figure out how to get Eclipse to change all the
    "extends CayenneDataObject" to "extends MyDataObject".

    Thanks for the good discussion!
    Todd

    On Mar 13, 2005, at 6:35 PM, Bryan Lewis wrote:

    >> I still have to either manually do it every time, or do something like
    >> override getStudents() in the Course class (not the _Course) class...
    >
    > Yeah, that's basically it... we override the getter method for any
    > relationship we want sorted or filtered or otherwise modified. It's
    > not a
    > problem for us because we have lots of hand-crafted getter methods in
    > our
    > terminal classes, building up the bulk of our business logic. One more
    > method for sorting is insignificant. For you, it sounds like that
    > isn't so
    > common.
    >
    > Your original suggestion wasn't a bad one. Let's see, you could
    > implement a
    > "wedge" class (what the modeler calls a "DataObject Superclass") and
    > override CayenneDataObject's readProperty(). If the result of
    > super.readProperty() is instanceof List, and the first element is
    > instanceof
    > Comparable, you could call Collections.sort() on the List before
    > returning
    > it.
    >
    >
    > ----- Original Message -----
    > From: "Todd O'Bryan" <toddobrya..ac.com>
    > To: <cayenne-use..bjectstyle.org>
    > Sent: Sunday, March 13, 2005 5:12 PM
    > Subject: Re: getting a List of Comparables, feature request?
    >
    >
    >>
    >> On Mar 13, 2005, at 2:21 PM, Bryan Lewis wrote:
    >>
    >>> I don't know how much this will help you, but I'm taking your
    >>> question
    >>> as a
    >>> "best practices" question.
    >>>
    >> Thanks for being generous. In spite of my inability to ask it
    >> correctly, that is kind of the way I meant it. :-)
    >>
    >>> When we started rewriting our apps onto a Cayenne+Tapestry base, we
    >>> set
    >>> ourselves a rule that there would be no Cayenne-related code in the
    >>> page
    >>> classes. No cayenne imports in any source file that also has
    >>> tapestry
    >>> imports. This is something we learned from the headaches in our
    >>> previous
    >>> WebObjects implementation (even though the model/view separation was
    >>> moderately good there).
    >>>
    >>> This avoids the situation of query code being buried all over the
    >>> place.
    >>> The queries are all in the model layer, deployed in a separate
    >>> model.jar.
    >>> This gives us maximum reuse of queries. When we want a list to be
    >>> sorted in
    >>> a certain way (like a list of countries sorted by name), we do a
    >>> simple
    >>> addOrdering() in the one query method. I'm glossing over some
    >>> details, but
    >>> you get the idea.
    >>
    >> How do you avoid this? Do you have an entirely separate model in
    >> addition to the classes the Cayenne Modeler creates for you? If so,
    >> how
    >> do you keep it in sync with the Cayenne model? If not, then I think
    >> I'm
    >> doing roughly what you're doing. I have a Course object, say, and I
    >> want a list of all the students in it, so I call the auto-created
    >> aCourse.getStudents() method. My problem is that, even though I almost
    >> always want the Student objects sorted by name, and even made Student
    >> implement Comparable for this very purpose, I still have to either
    >> manually do it every time, or do something like override getStudents()
    >> in the Course class (not the _Course) class so that it does it. Oh,
    >> and
    >> in every other class (Club, Team, Assignment, and numerous others,
    >> given the fact that almost everything in a school is somehow related
    >> to
    >> a Student) where I might want to getStudents(). And similar issues
    >> occur with other objects in the model: class sections are almost
    >> always
    >> sorted by period, multiple choice answers are almost always sorted
    >> A-E,
    >> forum posts are almost always sorted by time of post, etc.
    >>
    >> Shouldn't something OO-related come to my rescue about right now? Or
    >> am
    >> I doomed to write Collections.sort(theList); over and over again
    >> throughout the application?
    >>
    >> Thanks,
    >> Todd
    >>
    >



    This archive was generated by hypermail 2.0.0 : Mon Mar 14 2005 - 05:28:47 EST