Saturday, April 9, 2011

What is it about

A new pattern that I came across at work and decided to give a name to it.

The example domain I will use to explain the patten is

                               Vegetable (Parent Entity)

                                Vitamin (Child Entity and many to one relationship with parent entity)                              

Currently,  in most of our applications we perform deletes by updating a delete indicator flag and don't actually delete the row/Entity (for auditing purposes). In some cases we might end up having rows which contain the same information as existing rows which are marked for deletion. 

When retrieving the rows from the database we filter them, by using Hibernate Filters. and as a result an application user will not be aware of a deleted row.

The ressurection pattern will come into play when an update is performed on an Entity(Vegetable). Hence, in an update operation there would be 2 steps involved:
  1. retrieve the entity, without involving filters and retrieve all child entities (even those marked for deletion)
  2. update the entity/child entities with the new values

   After step one, we can determine if the values (Vitamins) that are being requested to be updated are not already present in the DB as deleted items. If they are present, then the existing row/Entity would be Resurrected by setting the delete indicator to true.

  The advantage of this pattern would be to add a little touch efficient storage in the database.

No comments:

Post a Comment