No recommendations?

Sean Dockery wrote:
I have an application that uses the ODMG personality of OJB. I query objects and collections using PersistenceBroker Criteria; the PersistenceBroker is obtained from a Transaction object (via TransactionExt). Objects are stored via a tx.lock plus a tx.markDirty call. The application uses the default cache implementation.

My question is: What should I use as the initial value of a collection field in newly created business objects?

Consider the following simple class:

public class Category {

private Collection products;

    public Collection getProducts() {
        return products;
    }

    public void setProducts(Collection newProducts) {
        products = newProducts;
    }

}

When I create the Category object and store it in the cache, the next fetch retrieves that same Category object reference that was stored. The products field is null because it was never initialized.

What value should I use when initializing the field? Can I use a plain old Collection of some sort (LinkedList, ArrayList, HashMap, et al) or are there some factory methods inside OJB from which I can obtain an instance of the default collection class.

One other thing: Because collection fields of objects retrieved from the database are typically of type RemovalAwareCollection, is it safe to replace the field value with a setProducts(plainOldList) or should I be modifying the collection via getProducts().add() and getProducts().remove()? Does it matter?


These two questions seem related (to me) by the fact that if I use a standard Collection subclass when I create an object and store it in the cache, it will never see a RemovalAwareCollection (for example) until the object has been purged from the cache and reloaded.


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



Reply via email to