Ronald,

can you please create a feature request at http://jira.codehaus.org/browse/CASTOR and attach the relevant parts of this thread (and a patch, if you happen to have some time .. ;-))

Werrner

Ronald Rudy wrote:

-----Original Message----- From: Bruce Snyder [mailto:[EMAIL PROTECTED] Sent: Monday, May 16, 2005 4:52 PM To: [email protected] Subject: Re: [castor-dev] Ordering objects in one-to-many relationship..



On 5/16/05, Ronald Rudy <[EMAIL PROTECTED]> wrote:

Can I assume based on the lack of responses that there is no way to sort
these collections via Castor?


-----Original Message----- From: Ronald Rudy [mailto:[EMAIL PROTECTED] Sent: Monday, May 16, 2005 9:55 AM To: [email protected] Subject: [castor-dev] Ordering objects in one-to-many relationship..

I have a simple object that has as an attribute an arraylist of many

'child'

objects based on a foreign key.  This works perfectly fine with the
following mapping syntax:

  <class name="com.xyz.ParentObject" identity="parentId"
key-generator="SEQUENCE">
     <description>"Parent Object"</description>
     <map-to table="parent"/>
     <cache-type type="none"/>
     {...}
     <field name="children" type="com.xyz.ChildObject"
collection="arraylist">
        <sql many-key="parent_id"/>
     </field>
     {...}
  </class>

This loads perfectly fine without issue, but what I'd like to do is order
the arraylist that is generated based on two identified columns.  Is this
possible without manually reordering the collected arraylist?

Ronald,

Castor does not provide a manner in which to sort the objects in a
collection. The only solution I can I think of is to pass in an ORDER
BY clause in the OQL query. Beyond that maybe we could consider
creating an optional order-by attribute on the field element only for
use with fields of a collection type.

Bruce
--
perl -e 'print

unpack("u30","D0G)[EMAIL PROTECTED]&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"

);'

The Castor Project
http://www.castor.org/

Apache Geronimo
http://geronimo.apache.org/


That would probably be the most logical and efficient way to do it.
However, it would also be possible to plug into Java's native
'java.lang.Comparable' based sorting, producing a collection object that
implements the java.util.SortedSet interface.  This would be datasource
independent, though it comes at a processing cost.  Supporting both would be
possible, and perhaps preferable, to give options.

As for now, I'll just use a separate manager object that uses OQL to load
and sort the collection manually.

-Ron





Reply via email to