I had a brief experience with collection="array" the other day.  Here's the skinny:

public class ArrayTest
{
        private Foo[] _foos;

        public Foo[] getFoos()
        {
                return _foos;
        }

        //THIS IS REQUIRED
        public void setFoos(Foo[] foos)
        {
                _foos = foos;
        }
}

<mapping>
        <class name="ArrayTest">
                <map-to xml="ArrayTest"/>

                <field name="foos" type="Foo" collection="array">
                        <bind-xml name="foo"/>
                </field>
        </class>
</mapping>


So, if I create an ArrayTest object and marshall it you get:
<ArrayTest>
        <foo>...</foo>
        <foo>...</foo>
        <foo>...</foo>
</ArrayTest>


Now when you unmarshall this, an ArrayTest is created, but setFoos() is called 3 times 
:(  You get a call for each element of the array, with all the elements processed so 
far, so the 1st call has 1 element in the array, the 2nd 2, the 3rd 3 and so on.
        --m


-----Original Message-----
From: Bruce Snyder [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 18, 2002 5:58 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] mapping - collection types


This one time, at band camp, Jamie De Wet said:

JDW>In the abstract class TransactionType -- Castor creates a Vector
JDW>financialList; -- the return type of the method getFinancial() is
JDW>Financial[] -- eg.
JDW>
JDW>public Financial[] getFinancial()   {
JDW>        int size = _financialList.size();
JDW>        Financial[] mArray = new Financial[size];
JDW>        for (int index = 0; index < size; index++) {
JDW>            mArray[index] = (Financial) _financialList.elementAt(index);
JDW>        }
JDW>        return mArray;
JDW>}
JDW>
JDW>My problem comes in using mapping file where I don't know how to set the
JDW>collection if my return type in my class is Financial[] and not something
JDW>like Vestor, Array, Enumeration etc.
JDW>
JDW>eg of Mapping
JDW><mapping>
JDW>    <class name="jdo.databinding.Transaction" identity="ddId">
JDW>            <description>Transaction</description>
JDW>            <map-to table="transaction" xml="transaction"/>
JDW>            <field name="ddId">
JDW>                    <sql name="dd_id" type="integer"/>
JDW>                    <bind-xml name="ddId" node="attribute"/>
JDW>            </field>
JDW>            <field name="name">
JDW>                    <sql name="name"/>
JDW>                    <bind-xml name="name" node="element"/>
JDW>            </field>
JDW>            <!-- Transaction has reference to Financial - many
JDW>financials per transaction  -->
JDW>            <field name="financial" type="jdo.databinding.Financial"
JDW>collection="Vector">    ------ problem using this line as my collection
JDW>should be Financial[]
JDW>                    <sql many-key="trans_id"/>
JDW>                    <bind-xml name="financial" node="element"/>
JDW>            </field>
JDW>    </class>

Jamie,

I've not used Arrays myself, but have you tried setting the
collection attribute to array instead of vector?

    http://www.castor.org/jdo-mapping.html#The-%3Cfield%3E-element

I'm curious to know the outcome of this so that I can provide an example
of using an array as a collection.

Bruce
-- 
perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to