I've added a virtual field before, so that can work for off-line ordering.
There's probably other ways to handle it as well:
public static void orderList(List objects, List orderings) {
Collections.sort(objects, ComparatorUtils.chainedComparator(orderings));
}
Note that this is all standard non-Cayenne java. The orderings are
simply objects that implement Comparator. You can either pass a
non-Ordering Comparator, or you can subclass Ordering and implement
your own compareTo().
(It looks like for 3.0, Ordering subclasses are required:
public static void orderList(List<?> objects, List<Ordering> orderings) {
Collections.sort(objects, ComparatorUtils.chainedComparator(orderings));
}
)
If I were redoing it today, I'd probably consider a subclass of Ordering.
On 5/18/08, Adrian Wiesmann <awiesman..omap.org> wrote:
> Hello list
>
> Instead of writing three separate mails I thought it would make sense to
> pack these three questions together:
>
> Ordering
> --------
> I am having a list of DataObjects where one field represents a human
> readable Id. Something like this:
>
> "1.1.1" (as example)
>
> When using the (offline) ordering mechanism of Cayenne to order a list of
> DataObjects, things get ugly when I am introducing numbers above 10. Like
> the following example:
>
> 1.1.1
> 1.1.2
> 1.10.1
> 1.10.2
> 1.2.1
> 1.2.2
>
> I would like to have the 1.10.x numbers below the 1.2.x numbers. Which
> means I would like to sort mathematically and not alphabetically.
>
> Is there any possibility to tell Cayenne to sort differently? Or would I
> need to add a new (virtual) field to the DataObject with a clean sort
> number and have Cayenne sort that field instead?
>
>
> Optimistic Locking
> ------------------
> My DataObjects contain a datetime field and a string field which both are
> used for optimistic locking. Basically the fields contain the datetime of
> the last change plus the user Id of the user persisting the change.
>
> When using optimistic locking with Derby everything works as expected.
> When using the same code and configuration with PostgreSQL (7 and 8) I
> receive an optimistic locking failure although nothing has changed on the
> database in the meantime.
>
> When I then remove the datetime field only from the optimistic locking
> check things work as expected.
>
> Has anybody experienced the same? Is this a known problem or am I missing
> something?
>
>
> QueryTable
> ----------
> We were discussing that on this list before. I am looking for a way to
> generate DataObjects without a reference to a table in the database.
> Something like a virtual DataObject.
>
> My usage scenario is it to have a DataObject which can be bound to the UI
> but which is only used to prepare data for a query and never should be
> persisted to the database.
>
> I remember some discussion about introducing some kind of inheritance to
> Cayenne which would support my usage scenario. I just wanted to check back
> with you if something already happened there?
>
> Thanks for your help.
>
> Cheers,
> Adrian
>
> P.S: Andrus: I remember you talking about being interested in learning
> about experiences with Apache Wicket? The Wicket Framework is great and
> using it with Cayenne works like a charm. Wicket is really a webframework
> done right!
>
This archive was generated by hypermail 2.0.0 : Mon May 19 2008 - 11:00:29 EDT