Set current row after commit/rollback (with a twist)

One of the most common requirements from user experience perspective is to keep the currently edited row selected after commit or rollback, or mark the newly created row as the current row.

For edit use-case, this is quite simple to achieve.
Step 1: Store the current row key.
Step 2: Edit record and commit.
Step 3: Execute query.
Step 4: Set the old row as the current row in the Row Set.

Here's a code snippet:

Does this logic holds good for new rows?. Well yes, almost!

Imagine this scenario:
1. You have a table of employees with a search option. You have searched for department id 10. That shows up all employees from department id 10.
2. Now you create a new employee, but this time, for department 20.
3. Now, after commit, you try to set the set the new row as the current row.
Now you get an exception! oracle.jbo.RowNotFoundException: JBO-25020:View row of key oracle.jbo.Key[201] not found in EmployeesVO1Iterator.

Quite obvious, isn't it? The new employee from department 20 does not exist in the current Row Set of employees from department 10.

So you need to write a simple validation to check if the newly created row exists in the current row-set, and set it as the current row only then. Thus all you need to do is to find a row with the old row key from the current row set. If the new row does not exist in the current row set, you may catch an ArrayIndexOutOfBoundsException.

So that's it. Use a safe commit logic to ensure the current row is never lost. Trust me, this small step is a giant leap for user experience.

The entire commit logic is posted below. Enjoy!