You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Adrian Wiesmann <aw...@somap.org> on 2008/11/16 18:30:38 UTC

Adding own ordering algorithm

Hello all

I have a field in a DataObject which I need for ordering and which is
formatted like this:

<number>.<number>.<number>

When ordering with the default Java order mechanism this problem arises.
The numbers are ordered like that (which is wrong in this context):

10.10.10
10.4.10
10.9.10

So I need to write my own comparator. Has anybody done so with Cayenne
before and what would you declare as the best/cleanest solution to do so?
Subclassing Ordering, extending the compare method and use that new class?

Thanks for your comments.

Cheers,
Adrian

Re: Adding own ordering algorithm

Posted by Tore Halset <ha...@pvv.ntnu.no>.
On Nov 17, 2008, at 6:07 PM, Adrian Wiesmann wrote:

> I never said the ordering per-se is. But I asked if (and how) anybody
> subclassed the Ordering class or if there is a cleaner method of  
> doing so
> with Cayenne.

Except from changing your db layout, I think your best bet is to just  
implement Comparable.

  - Tore.


Re: Adding own ordering algorithm

Posted by Adrian Wiesmann <aw...@somap.org>.
Hello Juergen

Thanks for your feedback.


> So I think this is not a cayenne-problem ...

I never said the ordering per-se is. But I asked if (and how) anybody
subclassed the Ordering class or if there is a cleaner method of doing so
with Cayenne.

Cheers,
Adrian

Re: Adding own ordering algorithm

Posted by Juergen Saar <ju...@jsaar.org>.
The 'normal' way of ordering is done by database.

In your special case there is problem in database-design,
not in the ordering itself.

There should be 3 columns in database to get a perfect ordering.

The other way is ordering with the java classes for ordered maps,
there you can write your own Comparator,
but this way should only be choosen on small result lists.

The third way is to create a view in database,
where this field is reformatted so that it can
be used for 'order by'.


So I think this is not a cayenne-problem ...
- Juergen -

2008/11/16 Adrian Wiesmann <aw...@somap.org>

> Hello all
>
> I have a field in a DataObject which I need for ordering and which is
> formatted like this:
>
> <number>.<number>.<number>
>
> When ordering with the default Java order mechanism this problem arises.
> The numbers are ordered like that (which is wrong in this context):
>
> 10.10.10
> 10.4.10
> 10.9.10
>
> So I need to write my own comparator. Has anybody done so with Cayenne
> before and what would you declare as the best/cleanest solution to do so?
> Subclassing Ordering, extending the compare method and use that new class?
>
> Thanks for your comments.
>
> Cheers,
> Adrian
>

RE: Adding own ordering algorithm

Posted by Scott Anderson <sa...@airvana.com>.
If you google for a comparator for version numbers/SNMP OIDs, you can
find Java classes to do this. If you're guaranteed to always have
exactly three fields, the slickest way would be to change the schema.

Regards,
Scott

-----Original Message-----
From: Adrian Wiesmann [mailto:awiesmann@somap.org] 
Sent: Sunday, November 16, 2008 12:31 PM
To: user@cayenne.apache.org
Subject: Adding own ordering algorithm

Hello all

I have a field in a DataObject which I need for ordering and which is
formatted like this:

<number>.<number>.<number>

When ordering with the default Java order mechanism this problem arises.
The numbers are ordered like that (which is wrong in this context):

10.10.10
10.4.10
10.9.10

So I need to write my own comparator. Has anybody done so with Cayenne
before and what would you declare as the best/cleanest solution to do
so?
Subclassing Ordering, extending the compare method and use that new
class?

Thanks for your comments.

Cheers,
Adrian