Thomas Dudziak wrote:

David Zejda wrote:

You have a missing quotation mark for the collection-class attribute,


thanks for a quick reply - sorry about my blindness


No problem, happens to all of us :-)

Btw, I don't think that TreeSet works as the collection-class, you should use one of the classes provided by OJB. Same for using SortedSet as the variable type - you have to use Set here. You shouldn't need to specify TreeSet as the collection-class anyway as OJB maintains the order that the objects are inserted. So you should be fine with


>
>    /**
>     * @ojb.collection element-class-ref="oit.ucase.DepositIndulgence"
>     *                 foreignkey="deposit_id"
>     *                 auto-retrieve="true"
>     *                 auto-update="true"
>     *                 auto-delete="true"
>     */
>    private java.util.Set indulgences = new java.util.TreeSet();

OK, but imagine the scenario:

1) TreeSet created, a few objects inserted by program (and ordered).
2) Persisted.
3) Retrieved from DB, OJB creates it's own (non-sorted) Set, inserts objects in correct order.
4) Several more objects inserted by program. I guess, they will not be sorted (and it's a problem)..


possible solutions:
a) use non-sorted set as a persistent one and sort it independently on persistence (by wrapper SortedSet or somehow..)
b) create OJB-capable SortedSet and use that one as e collection-class


Then I'd say, go for option b, e.g. create a ManageableTreeSet or DTreeSet (depending on your requirements). Have a look at the source of ManageableHashSet and DSetImpl for pointers.
If you'd be willing to, we could include your class in OJB as it probably is useful for other people, as well.

There is nothing special on it, but if you say, it's here..
BTW I think it would be better to send it to ojb-dev, but currently I'm not a subscriber and it seems to be useless to subscribe only becouse of such nit..


/* Copyright 2002-2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.ojb.broker.util.collections;

import org.apache.ojb.broker.ManageableCollection;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerException;

import java.util.Collection;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Iterator;

/**
* is a utility class. provides a SortedSet that addionally implements
* the ManageableCollection interface. This class may be used
* as a type for collection attributes.
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Zejda<a>
*/
public class ManageableTreeSet extends TreeSet implements ManageableCollection
{


    /** Creates a new instance of ManageableSortedSet */
    public ManageableTreeSet(Collection c)
    {
        super(c);
    }

    /** Creates a new instance of ManageableSortedSet */
    public ManageableTreeSet(Comparator c)
    {
        super(c);
    }

    /** Creates a new instance of ManageableSortedSet */
    public ManageableTreeSet(SortedSet s)
    {
        super(s);
    }

    /** Creates a new instance of ManageableSortedSet */
    public ManageableTreeSet()
    {
        super();
    }

/**
* add a single Object to the Collection. This method is used during reading Collection elements
* from the database. Thus it is is save to cast anObject to the underlying element type of the
* collection.
*/
public void ojbAdd(Object anObject)
{
super.add(anObject);
}


/**
* adds a Collection to this collection. Used in reading Extents from the Database.
* Thus it is save to cast otherCollection to this.getClass().
*/
public void ojbAddAll(ManageableCollection otherCollection)
{
super.addAll((ManageableTreeSet) otherCollection);
}


public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
{
//do nothing
}


/**
* returns an Iterator over all elements in the collection. Used during store and delete Operations.
* If the implementor does not return an iterator over ALL elements, OJB cannot store and delete all elements properly.
*
*/
public Iterator ojbIterator()
{
return super.iterator();
}
}


Tom
David

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



Reply via email to