On Thu, Nov 26, 2009 at 12:52 PM, Lachlan Deck <lachlan.dec..mail.com> wrote:
> 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.
Sometimes application code needs access to this and making it private
wouldn't help that matter.
> 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)?'
Well, an object should only be marked for deletion if it needs to be
deleted (it exists in the DB). So Cayenne is working properly in this
regard. If an object has never been persisted (does NOT exist in the
DB), then it is marked as transient if you delete it.
> 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.
By context I assume you mean data/object context. My previous comment
still applies. :-) The DataContext needs to know what to do when you
commitChanges(). If an object's persistence state is set to DELETED,
then the DC knows it needs to issue a DELETE to the DB on
commitChanges() (TRANSIENT objects will not be persisted). The
JavaDoc even specifies this:
/**
* Describes a state of an object registered with
DataContext/ObjectContext, that will
* be deleted from the database on the next commit.
*/
public static final int DELETED = 6;
Here is TRANSIENT:
/**
* Describes a state of an object not registered with
DataContext/ObjectContext, and
* therefore having no persistence features.
*/
public static final int TRANSIENT = 1;
If you register an object with a DC and then delete it (without ever
persisting it), then it becomes TRANSIENT. If you register an object
with a DC, commit it, then delete it, it becomes DELETED. Keep in
mind the DC exists to manage your objects for committing changes to
the DB, not to track general Java usage (such as removing an object
from a collection).
mrg
This archive was generated by hypermail 2.0.0 : Fri Nov 27 2009 - 10:02:06 EST