Re: delete new --> transient?

From: Lachlan Deck (lachlan.dec..mail.com)
Date: Thu Nov 26 2009 - 12:52:34 EST

  • Next message: Joe Baldwin: "Exception Deleting DataObject with to-many relationship"

    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() {
            return
            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 <lachlan.dec..mail.com>
    >
    >> Hi there,
    >>
    >> just wondering why when deleting a new object that its status is being set
    >> to PeristenceState.TRANSIENT rather than DELETED?
    >>
    >>..ee 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



    This archive was generated by hypermail 2.0.0 : Thu Nov 26 2009 - 12:53:12 EST