A composite ViewObject based on multiple data sources

Sometimes you may need to display data from different data sources on a single row. Say for example, part of the row from database and a couple of attributes from a third party data source. ADF BC let you to customize the ViewObject to compose data from different sources by overriding a couple of 'life cycle' methods. Below given sample code illustrates the same. Here, you can see that EmployeesViewObject tries to get value for 'LocationDetails'(transient attribute on Employee ViewObject) from a third party data source exposed through some custom APIs.


/**
* executeQueryForCollection - overridden for custom java data source support.
*/
protected void executeQueryForCollection(Object qc, Object[] params,
                     int noUserParams) {
  thirdPartyDataSource.filterOutValues(params);
  super.executeQueryForCollection(qc, params, noUserParams);
}

/**
* createRowFromResultSet - overridden for custom java data source support.
*/
protected ViewRowImpl createRowFromResultSet(Object qc,
                     ResultSet resultSet) {
  EmployeesViewRowImpl rowImpl = (EmployeesViewRowImpl)super.createRowFromResultSet(qc, resultSet);
  rowImpl.populateAttribute(EmployeesViewRowImpl.LOCATIONDETAILS, 
  thirdPartyDataSource.getValueForAttribute
    (EmployeesViewRowImpl.AttributesEnum.LocationDetails.toString(), 
        rowImpl.getKey().getAttributeValues()));
  return rowImpl;
}

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS2 + HR Schema]

Comments

Post a Comment