cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lachlan Deck <>
Subject Re: delete new --> transient?
Date Thu, 26 Nov 2009 17:52:34 GMT
On 27/11/2009, at 2:24 AM, Andrey Razumovsky wrote:

> Because for deleted objects DELETE query will be forced, and if you create
> (register), then delete (unregister) an object it looks like as if it was
> never registered in context.

This seems (to me, at least) to be implementation details of the framework that's overly exposed
to general users ('cause you have to know the implementation details in order to make any
use of those persistence states in any meaningful way.... e.g., what does transient mean?
Well it depends.... What does deleted mean? Again it depends on other conditions.). Perhaps
then PersistenceState should be private to the framework.

But this still means that there's no 'general purpose' method that I'm aware of (e.g., in
Cayenne 'the new static helper' ... ah, see, if you'd called it CayenneUtils or PersistentUtils
there'd be no need for further clarification of what Cayenne refers to via email ;-)  which
answers the basic question: 'is this object marked for deletion (regardless of whether it
was previously persisted)?'

> Why you need such testing?

I simply want to know if an object is marked for deletion within the context. It should be
simple like the question itself. :)    And to answer the question, because I need to know
at a later point whether to replace the object with a new one.

i.e., there's basic questions that are generally useful:
isNew, isModified, isDeleted.

> Currently I can think only of quite nasty
> workaround on ROP 3.0 - using custom contexts and overriding deleteObject()

I ended up having to do:
public boolean isDeleted() {
	getObjectContext() == null
	|| getObjectContext().deletedObjects().contains(this)
	|| !getObjectContext().getGraphManager().registeredNodes().contains(getRecord());

It's a bit unintuitive imho for deletedObjects to not contain these things ... for surely
they could be dealt with (i.e., treated as unregistered) during the saveChanges operations
should an object be both new and deleted(?)....

> 2009/11/26 Lachlan Deck <>
>> Hi there,
>> just wondering why when deleting a new object that its status is being set
>> to PeristenceState.TRANSIENT rather than DELETED?
>> @see ObjectContextDeleteAction#deleteNew(Persistent)
>> It also doesn't turn up in context.deletedObjects
>> So this all seems to make it more difficult to determine the state of an
>> object.
>> Regardless of the rationale - what's the recommended way of determining if
>> an object is deleted within the context?
>> Thanks.
>> with regards,
>> --
>> Lachlan Deck
> -- 
> Andrey

with regards,

Lachlan Deck

View raw message