Tuesday, January 29, 2013

Method - createInstanceFromResultSet() for ADF BC Database Fetch Monitoring

ADF application performance tightly coupled with database interaction performance - data fetching from database. It might be useful to monitor and locate VO's with large data fetch, this would help to restrict size of fetched data collections. There is one special method in ADF BC - createInstanceFromResultSet(), you can override it in VO Impl class - method is invoked for each row fetched from database. I will explain how it works, I will be using ADF BC last() operation - this operation is perfect example of possible slow performance in ADF.

Download sample application - ADFScrollingToLastApp.zip. Employees VO Impl class contains overridden method for  createInstanceFromResultSet():

It is enough just to log method invocation - one invocation per on row fetched.

Sample application contains basic custom method to call last() operation - imagine in our use case we need to retrieve last row for certain calculations:

Run ADF BC tester and open Employees VO. 2 rows are fetched initially:

Invoke our custom method calling last() operation - all the rows from the very first one till the last one will be fetched. This is why last() operation is known for poor performance - before returning actual last row, it fetches entire rowset. It may cause serious problems for large data sets, be careful:

So, in this case createInstanceFromResultSet() gave us very accurate info about how many rows were fetched.

Let's run the same application and access ADF UI. Form data is loaded and first row is displayed:

In the background we can see that 25 rows were fetched during initial form access:

This is correct - its how is set RangeSize, equal to 25:

Imagine if by mistake you set RangeSize = -1, it will fetch all rows, this can be critical for large datasets.

Go to the last row - press Scroll To Last button:

All the rows are fetched, before last row is retrieved:

If your ADF application performs slow, override createInstanceFromResultSet() and check how many rows are fetched. May be all rows are fetched during initial access.

No comments: