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 : Sun Mar 13 2005 - 17:13:00 EST