cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: String-with-number sort and insert order preservation
Date Wed, 03 Feb 2010 13:44:05 GMT
Some databases support VIEWs.   You can make your database view parse
and sort your varchar field into four fields.

But you have to treat inserting/updating a record differently than
viewing it if you go this route.

On Tue, Feb 2, 2010 at 7:45 PM, Marek Šabo <msabo@buk.cvut.cz> wrote:
> Hi all,
>
> I would like to ask you two questions:
>
> 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?
>
> 2) I was filling ip table with available ranges like this:
>
> ObjectContext oc = DataContext.getThreadObjectContext();
>
>        for (int i = 33; i < 255; i++) {
>
>            Ip4Address ip = oc.newObject(Ip4Address.class);
>
>            ip.setIpAddress("XX.XX.XX." + i);
>
>            ip.setUsed(Boolean.FALSE);
>
>            ip.setNat(Boolean.FALSE);
>
>        }
>
> but cayenne inserted rows like this (probably hashed order for
> optimization):
>
> INFO  - QueryLogger                - [bind: 1->ipAddress:'XX.XX.XX.97', 2->nat:'false',
3->used:'false']
>
> INFO  - QueryLogger                - Generated PK: Ip4Address.id = 1
>
> INFO  - QueryLogger                - === updated 1 row.
>
> INFO  - QueryLogger                - [bind: 1->ipAddress:'XX.XX.XX.71', 2->nat:'false',
3->used:'false']
>
> INFO  - QueryLogger                - Generated PK: Ip4Address.id = 2
>
> INFO  - QueryLogger                - === updated 1 row.
>
>
> Is there any way how to override this mechanism in order to preserve
> order of inserted rows?
>
> TIA,
>
> --
> Marek Šabo
>
>

Mime
View raw message