If anyone is interested, my current solution for one case is:
 1. add an Integer field listIndex to the item object
 2. make the item object PersistenceBrokerAware, and in the
beforeUpdate() method
        // update the position of this entry in the list
        if (this.parent != null) {
            this.listIndex = new
Integer(this.parent.getItemList().indexOf(this));
        } else {
            this.listIndex = null;
        }
 3. to the parent collection-descriptor decalaration, add <orderby
name="listIndex"/>
 
Possible issues:
 1. If the order of items in a list is changed, then _all_ the item
objects must be updated so their indexes are stored.

As always, suggestions are welcome.

Thanks,

Rob :)


> -----Original Message-----
> From: Coup, Robert Muir [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, 14 January 2004 12:09 p.m.
> To: [EMAIL PROTECTED]
> Subject: Ordered Collections, Lists, DList
> 
> 
> Hi all,
> 
> What is the best way of storing an ordered list without using 
> Dlist which requires additional tables & SQL lookups? 
> 
> OrderBy works great if the positioning has some underlying 
> field (eg. Object id, name) but if the only thing specifying 
> the position is the list index then it doesn't work too well.
> 
> One option is to link a fake field-descriptor to the item's 
> position in a list and use orderby... Is this what other 
> people are doing?
> 
> Another is to create a new ManageableCollection that is 
> linked somehow to a database field which it stores indexes 
> in... but that breaks the idea that the mapping is in the repository.
> 
> Another is to do something like...
>       <collection-descriptor 
>        name="myList"
>        element-class-ref="com.example.MyObject"
>        collection-class="com.example.MyMagicList"
>        index-field="listIndexField"
>        />
> Then store the index of each item in the list in the database 
> field specified by index-field. When you re-instantiate it is 
> effectively an orderBy. A ManageableList interface extending 
> ManageableCollection may be needed which knows about and uses 
> the index-field attribute... 
> And it probably needs to ignore/complain about additional 
> orderBy fields...
> 
> Is this a good idea? Something worth doing?
> Or am I missing the obvious?
> 
> Thanks again,
> Rob :)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to