Tuesday, March 27, 2007

Programmatically removing all entities from a view object

Recently I had a case where I needed to remove all rows from a view object and found that there was no existing method to do this.
The case for doing such an action is where there is a Master-Detail relationship and the detail relation is used only of there is a certain condition met in the master. If the condition is met then the detail is required, however if the user changes their mind then we need a way of removing any records that may have been created in the detail.

By adding the following method in the View Object Implementation class we can safely delete all records in the view object:

    public void removeAllRows(){
// rangeSize is -1
Row[] rows = getAllRowsInRange();
for (int r = 0; r < rows.length; r++)
if (rows[r] != null)
rows[r].remove();

}

No comments: