Performing Logical Deletes

From: Gary Jarrel (garyjarre..mail.com)
Date: Wed Feb 15 2006 - 01:54:24 EST

  • Next message: Ryan Holmes: "Re: serialVersionUID in autogenerated classes?"

    Hi All!

    I'm after some advice on how to perform a logical delete. A number of
    tables in db and subsequently cayenne java objects have a "deleted"
    property. The purpose of this property is that records with this
    property set to true appear as deleted to the application (or do not
    appear at all). I've got a LogicallyDeletable interface which marks a
    particular object as "Logically Deletable" hence the delete operation
    on such object shouldn't remove the record from the DB but set a the
    deleted field to true.

    After some consideration, I was thinking of overriding the
    deleteObject method in the DataContext. The new method would check
    whether the object is instanceof LogicallyDeletable and if so simply
    set the deleted property to true, otherwise it would perform the
    normal deletion. Do you think this would be a viable solution?

    I suppose another feature that I may be able to achieve is in a
    cascade delete operation whether by overriding the deleteObject method
    certain records which are not instanceof LogicallyDeletable would be
    deleted as normal and the ones that are will simply have the deleted
    field modified.

    Looking at the Cayenne source I can see that this may have
    repercussions on the persistent states. Now I would assume that if I
    set the persistent state of a logically deletable object to DELETED,
    then upon commit, the record would actually be deleted from the
    database? However if I don't then a cascaded delete might cause a
    recursion problem? Any solutions?

    Anyway, thought someone may have done something similar, any
    ideas/advice would be appreciated!

    Thank you!

    Gary



    This archive was generated by hypermail 2.0.0 : Wed Feb 15 2006 - 01:54:28 EST