Re: CayenneDataObject#setDataContext()

From: Kevin Menard (kmenar..ervprise.com)
Date: Tue Sep 27 2005 - 20:59:50 EDT

  • Next message: Andrus Adamchik: "Re: CayenneDataObject#setDataContext()"

    On 9/14/05 10:00 AM, "Cris Daniluk" <cris.danilu..mail.com> wrote:

    > When setDataContext() is called, the DataContext should know its going
    > to be holding the CDO. Couldn't setDataContext check the object store
    > and see if the CDO is already in there. Then it could throw an
    > exception if not, preventing the confusing situation...
    >
    > This may not work, especially with serialization, etc.. just a random idea.

    I've prepared a patch around this idea. Any comments on it would be greatly
    appreciated. The new setDataContext() looks like:

    public void setDataContext(DataContext dataContext) {
        if (dataContext == null) {
            this.persistenceState = PersistenceState.TRANSIENT;
        }

        else {
            if ((null == dataContext.getObjectStore()) ||

                  (!dataContext.getObjectStore().getObjects().contains(this))) {

            throw new CayenneRuntimeException("Object is not registered with
    data context. Register the object prior to calling this method.");
            }
        }

        this.dataContext = dataContext;
    }

    Apologies for the poor formatting.

    This change breaks a lot of tests though. I don't have a problem going
    through and fixing them, but I want to make sure this is the right way to be
    going before I waste my time.

    Thanks,
    Kevin



    This archive was generated by hypermail 2.0.0 : Tue Sep 27 2005 - 20:59:58 EDT