In this post I'm sharing a simple example illustrating the 'soft deletion' of rows and undoing the delete later if the user opts for. The business use case requirement is that, whenever end user delete rows, system should not delete these rows from the underlying data base table, rather should mark(update) them as deleted. Later user can undo the deletion to restore the deleted rows(this operation should not rollback the transaction)
Download
You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS4 + HR Schema]
A glance at the implementation
The 'Soft Delete' action has two steps,
1.The action first refreshes the row with database by calling row.refresh(Row.REFRESH_WITH_DB_FORGET_CHANGES) to discard the modifications that user might have done on the row before opting for delete(if any)
2. Next step is to remove the row from the iterator(effectively from entity object). Deleted row keys are stored in an ArrayList for performing 'undo' operation if needed.
Later when user commits transaction, entity instance will check for operation flag and will change it to UPDATE if the value is DELETE, and would flag an attribute as well to enable soft delete at database table level. In the above sample commits action updates DepartmentName attribute by prefixing '[DELETE]' token . The view object query has necessary where clause added to remove the soft deleted rows from the result list.
The roll back action of deleted rows refreshes the deleted entity rows with data base to restore them back to the original state.
Learn More ...
There are a lot more points like this. If you are curious to learn the internals of the ADF Business Components and ADF Binding Layer, the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html
Download
You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS4 + HR Schema]
A glance at the implementation
The 'Soft Delete' action has two steps,
1.The action first refreshes the row with database by calling row.refresh(Row.REFRESH_WITH_DB_FORGET_CHANGES) to discard the modifications that user might have done on the row before opting for delete(if any)
2. Next step is to remove the row from the iterator(effectively from entity object). Deleted row keys are stored in an ArrayList for performing 'undo' operation if needed.
Later when user commits transaction, entity instance will check for operation flag and will change it to UPDATE if the value is DELETE, and would flag an attribute as well to enable soft delete at database table level. In the above sample commits action updates DepartmentName attribute by prefixing '[DELETE]' token . The view object query has necessary where clause added to remove the soft deleted rows from the result list.
The roll back action of deleted rows refreshes the deleted entity rows with data base to restore them back to the original state.
Learn More ...
There are a lot more points like this. If you are curious to learn the internals of the ADF Business Components and ADF Binding Layer, the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html
No comments:
Post a Comment