Oracle® Application Development Framework Developer's Guide For Forms/4GL Developers 10g (10.1.3.1.0) Part Number B25947-01 |
|
|
View PDF |
For auditing purposes, once a row is added to a table, sometimes your requirements may demand that rows are never physically deleted from the table. Instead, when the end-user deletes the row in the user interface, the value of a DELETED
column should be updated from "N
" to "Y
" to mark it as deleted. This section explains the two method overrides required to alter an entity object's default behavior to achieve this effect. The following sections assume you want to change the Product
entity from the SRDemo application to behave in this way. They presume that you've altered the PRODUCTS table to have an additional DELETED
column, and synchronized the Product
entity with the database to add the corresponding Deleted
attribute.
To update a deleted flag when a row is removed, enable a custom Java class for your entity object and override the remove()
method to set the deleted flag before calling the super.remove()
method. Example 26-4 shows what this would look like in the ProductImpl
class of the SRDemo application's Product
entity object. It is important to set the attribute before calling super.remove()
since an attempt to set the attribute of a deleted row will encounter the DeadEntityAccessException
.
Example 26-4 Updating a Deleted Flag When a Product Entity Row is Removed
// In ProductImpl.java public void remove() { setDeleted("Y"); super.remove(); }
The row will still be removed from the row set, but it will have the value of its Deleted flag modified to "Y" in the entity cache. The second part of implementing this behavior involves forcing the entity to perform an UPDATE
instead of an INSERT
when it is asked to perform its DML operation. You need to implement both parts for a complete solution.
To force an entity object to be updated instead of deleted, override the doDML()
method and write code that conditionally changes the operation
flag. When the operation flag equals DML_DELETE
, your code will change it to DML_UPDATE
instead. Example 26-5 shows what this would look like in the ProductImpl
class of the SRDemo application's Product entity object.
Example 26-5 Forcing an Update DML Operation Instead of a Delete
// In ProductImpl.java protected void doDML(int operation, TransactionEvent e) { if (operation == DML_DELETE) { operation = DML_UPDATE; } super.doDML(operation, e); }
With this overridden doDML()
method in place to complement the overridden remove()
method described in the previous section, any attempt to remove a Product
entity through any view object with a Product
entity usage will update the DELETED
column instead of physically deleting the row. Of course, in order to prevent "deleted" products from appearing in your view object query results, you will need to appropriately modify their WHERE clauses to include only products WHERE DELETED = 'N'
.