You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Zvonimir Spajic <z....@ascensys.de> on 2006/08/17 16:11:07 UTC

sorting and ordering pk field in memory

Hello,

is there a nice way to sort a List of Cayenne-Objects on o  
primary-key-field, e.g. "id" (pk) in memory, because the user can resort  
the existing list more than one time. I don't want to read it out from DB  
every time.
This doesn't help:
	this.resultList = new ArrayList(this.resultList);		
	Ordering ordering = new Ordering("id", true);
	ordering.orderList(this.resultList);
In this example the ordering is not correct or will not be changed.

Can anyone help with this...or have a better idea...

Thank you
Zvonimir




Re: sorting and ordering pk field in memory

Posted by Andrus Adamchik <an...@objectstyle.org>.
The easiest way to order on a property that is not really a property  
is to create a cover getter for it in the persistent class:

public int getId() {
    return DataObjectUtils.intPkForObject(this);
}

Andrus

On Aug 17, 2006, at 10:11 AM, Zvonimir Spajic wrote:

> Hello,
>
> is there a nice way to sort a List of Cayenne-Objects on o primary- 
> key-field, e.g. "id" (pk) in memory, because the user can resort  
> the existing list more than one time. I don't want to read it out  
> from DB every time.
> This doesn't help:
> 	this.resultList = new ArrayList(this.resultList);		
> 	Ordering ordering = new Ordering("id", true);
> 	ordering.orderList(this.resultList);
> In this example the ordering is not correct or will not be changed.
>
> Can anyone help with this...or have a better idea...
>
> Thank you
> Zvonimir