You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marcin Skladaniec <ma...@ish.com.au> on 2007/01/25 05:37:24 UTC
deleteObject() and localObject() and object states
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
Re: deleteObject() and localObject() and object states
Posted by Marcin Skladaniec <ma...@ish.com.au>.
Hi Andrus
I'm using cayenne HEAD, built just week ago. I wonder if the fact
that you are seeing different behaviour has anything to do with fact
that my test is in "real" application, while yours is a junit test
with mockup objects ?
Marcin
On 30/01/2007, at 12:48 AM, Andrus Adamchik wrote:
> 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
>>
>
Marcin
Re: deleteObject() and localObject() and object states
Posted by Andrus Adamchik <an...@objectstyle.org>.
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
>