Re: deleteObject() and localObject() and object states

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Jan 29 2007 - 09:48:01 EST

  • Next message: Marcin Skladaniec: "Re: deleteObject() and localObject() and object states"

    Hi Marcin,

    Just got some time to try it out. I am seeing somewhat different
    (still incorrect) behavior (is this because of the difference in
    Cayenne version?). I need to investigate this some more, so I opened
    this bug report:

    http://issues.apache.org/cayenne/browse/CAY-742

    Andrus

    On Jan 25, 2007, at 6:37 AM, Marcin Skladaniec wrote:

    > Hello.
    > I just wanted to share my recent findings about deleteObject() and
    > localObject() in remote cayenne
    >
    > (assuming that there is only one apple in the db)
    >
    > Apple apple1 = (Apple)context1.performQuery(Apple.class).get(0);
    > Apple apple2 = (Apple)context2.performQuery(Apple.class).get(0);
    >
    > context1.deleteObject(apple1);
    > now:
    > context1.getGraphManager().registeredNodes() is empty
    > context2.getGraphManager().registeredNodes() is also empty which is
    > great, but
    >
    > apple2.getObjectContext() returns context2, and that is confusing...
    >
    > How come that the context lost reference to the object, but object
    > had not lost the reference to the context ? Is that a bug or some
    > limitation ?

    > also the apple2.getPersistenceState() is commited. I'm not clear at
    > all if that is difficult to change.
    >
    > this all leads to yet another problem, where
    > context3.localObject(apple2) gives a hollow object with some fields
    > filled, but the object cannot be faulted. (A nice
    > FaultFailureException is thrown, but it is sometimes too late.)
    > I'm overriding localObject behaviour in my application, but it
    > would be nice if cayenne dealt with it.
    >
    > My idea is to have two localObject methods:
    > - new localObject() could take Persistent as a parameter, this will
    > allow to check if the incoming object has a context and in what
    > persistent state is it:
    > * if getObjectContext() == null and getPersistentState() == NEW
    > than the object can be copied/inserted to the context
    > * if getObjectContext() != null and getPersistentState() =
    > COMMITTED or MODIFIED than the object can be copied/inserted to the
    > context
    > * else it cannot proceed, and some exception is thrown
    > - old localObject() could be more restrictive and throw Exception
    > instead of returning a HOLLOW object.
    >
    > Oh, and javadocs for localObject are a bit out of date: " (...)
    > *all* objects in the source *list* must be(...)"
    >
    > With regards
    > Marcin
    >



    This archive was generated by hypermail 2.0.0 : Mon Jan 29 2007 - 09:48:38 EST