cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Baldwin <jfbald...@earthlink.net>
Subject Re: String-with-number sort and insert order preservation
Date Wed, 03 Feb 2010 01:53:32 GMT
Marek,

> 1) Is there any way to sort varchar fields which happen to numbers, more
> precisely ipv4s?
> query.addOrdering(Ip4Address.IP_ADDRESS_PROPERTY, SortOrder.ASCENDING);
> This of course sets the hundreds as first in line, any tips on some
> custom sorting?

I have two ideas:

1.You could create a temp table with four int fields and convert your table, then sort on
the temp table. A DBMS will sort this abstraction much easier than a string representation.

2. (This idea might sound complex but I think it is the best alternative): You could try to
combine a SQL trick of casting a substring as an int, then building a select statement using
the Cayenne "#result" syntax and creating a converted-integer cayenne SQLTemplate query using
the SQL statement.  If you get this to work, then you can then simply append an "order by"
clause to your SQL statement that you send to the SQLTemplate and you are done!

BTW, I have never cast a substring (but it appears straightforward), however I have used the
Cayenne "#result" syntax with an order -by and a group-by clause and it works like a charm.
 This is a *very* cool feature of Cayenne.

It is important to build this one layer at a time and then test it.


> 2) I was filling ip table with available ranges like this:

Sorry, I don't understand this question.

Hope this helps,
Joe


Mime
View raw message