From: Gavin_King/Cirrus%<CI...@ci...> - 2002-08-07 05:26:59
|
>2. Related to 1, it would also be nice if the sort-order of a >collection could be specified at runtime in some way. So if I've >already queried for a customer and call getOrders on it I would like >to be able to choose how the orders are sorted when fetched. This at >runtime too because I might want them sorted differently on different >occations. Hmmmm. My main problem with this is trying to imagine what kind of API would be used to access such functionality. I suppose if the collection was lazily initialized, you could do something like: ( (HibernateCollection) orders ).sortBy("Order.total, Order.orderDate"); Then when the collection is loaded, the elements would be returned ordered by the given properties. I'm not so keen on this because of the necessity to cast the collection wrapper to a Hibernate API. This conflicts with the project ideology.... I guess you could do something like: session.presort(orders, "Order.total, Order.orderDate"); but this is still creating a dependency of application code upon the supposedly transparent lazy-initialization procedure. Someone else has requested that we be able to specify a collection sort order in the _mapping_ file (this is easily doable). But I have another reason for doubting the whole concept: You would have to have a *very* large collection for there to be any great performance issue in letting Java sort the collection! Hibernate already supports SortedMaps and SortedSets. If you needed to specify a Comparator at runtime (rather than in the mapping file), you could just grab the elements and put them in a new collection. Gavin |