I did this for my first Cayenne project.
I set up a restricting qualifier which filtered out all objects marked
as logically deleted. That prevented them from being seen by the
application. At the time this was handled by a DataContextDelegate
that added additional qualifiers to select expressions, but I believe
there are easier ways to specify this now.
Performing the delete was a little more tricky. I manually marked
the object deleted and committed the change, then invalidated the
object (and all references -- that was the tricky part).
However, I was not using delete rules for that project -- everything
was left at the default "No action" value.
I'll be interested in hearing how you handle this because the issue
will probably have to be addressed again in another future project.
On 2/15/06, Gary Jarrel <garyjarre..mail.com> wrote:
> 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 - 12:03:42 EST