db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guillaume Nodet" <guillaume.no...@deliasystems.com>
Subject RE: Collection prefetching patch
Date Wed, 04 Feb 2004 12:40:58 GMT

I submit another patch that corrects my problem:

In AbstractPersistentField, lines 321 -> 328 replace the code

            String name = fieldName.substring(0, index);
            PersistentField pField = createInternPersistentField(realClass,
name);
            Object attrib = pField.get(realObj);

            if (attrib != null || value != null)
            {
                if (attrib == null)
                {

by the following code:

            String name = fieldName.substring(0, index);
            PersistentField pField = createInternPersistentField(realClass,
name);
            Object attrib = pField.get(realObj);

            if (attrib != null
                || (value != null
                    && (!(value instanceof Collection) || ((Collection)
value).size() > 0)))
            {
                if (attrib == null)
                {

-----Message d'origine-----
De : Guillaume Nodet [mailto:guillaume.nodet@deliasystems.com]
Envoye : mercredi 4 fevrier 2004 09:40
A : OJB Users List
Objet : Collection prefetching patch


I saw that ojb do automatically create empty collections and set them to the
appropriate field even if they are empty.
In my own, case, this appears with nested objects, and thus it actually
creates the nested object despite the fact that it was null when i stored
the object.

Wouldn't it be better to create the collection only when it is not empty ?

In the CollectionPrefetcher, lines 213 -> 218, there is the following code:

                ManageableCollection col =
createCollection(collectionClass);
                for (Iterator it2 = list.iterator(); it2.hasNext();)
                {
                    col.ojbAdd(it2.next());
                }
                result = col;

What would be the impact to replace it with the following. IMHO, it would
improve performance a little, and avoid creating unnecessary collections.

                ManageableCollection col = null;
                for (Iterator it2 = list.iterator(); it2.hasNext();)
                {
                    if (col == null)
                    {
                        col = createCollection(collectionClass);
                    }
                    col.ojbAdd(it2.next());
                }
                result = col;

Another way to solve my problem is to implement my own PersistentField class
that avoids setting empty collections on nested object if they are not
created yet, but i guess the one above is better.

Regards,

Guillaume Nodet



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message