Saturday, March 12, 2016

ADF: Control rows which you want to commit

Problem Description: Let say you have a table in ADF and you want to make sure that even if user edits or create certain rows, they should not get committed but other rows should get committed. Generally when we do commit in adf all rows gets committed together but our requirement is to chose which records should get committed and which one should not.

In this blog I have a hypothetical usecase that all employees rows having firstname=Sanjeev should not get inserted. Its just frozen and no one should be able to modify them.
In ideal case we would like to throw error to end user and let him/her know why certain row can not be committed, but then real world is not ideal and there are chances that we don't want to show error but we silently want to make sure that certain rows (in our example where firstname=Sanjeev) are not getting inserted.

Solution: Its prettey simple. Use doDML method of EOImpl and do not call super.doDML for certain rows. This is doDML operation, which is going to fire actual insert/update/delete operation. If we don't call superclasses doDML operation that those operations will not happen for the row.

Step 1: Create EO/VO/AM based on employee table.

Step 2: Generate EOImpl and override doDML operation as shown below
    protected void doDML(int operation, TransactionEvent e) {
        if(operation == DML_INSERT && "Sanjeev".equals(this.getFirstName())){
            System.out.println("Do not commit employee rows having first name = sanjeev");
            super.doDML(operation, e);

Step 3: Run AM and tester in bc4j tester and show VO in tabular format

a. Create two new rows one having FirstName=Sanjeev and other FirstName=Sanjeev1

b. Commit transaction

c. Requery vo

You see there is only one row has got committed.

1 comment:

  1. Very wonderful article.In this information is getting wonderful reviews from the students .