10 Sept 2017

Using Custom View Objects with Entity Associations

While implementing business logic at ADF BC layer we leverage entity associations in our code as a convenient approach to manipulate entities that are related to each other by design. For example, there is DepartmentEmployeesEL association linking Department and Employee entities. In Department entity implementation class there is an association accessor returning a row iterator with employees working for this department:
  public RowIterator getEmployees()
    return (RowIterator) getAttributeInternal(EMPLOYEES);

This accessor can be used in a method iterating over all associated employees and performing some actions with each of them:
  private void processEmployees()
    RowIterator employees = getEmployees();
    while (employees.hasNext())
      EmployeeImpl employee = (EmployeeImpl) employees.next();
      // do something with employee
In order to retrieve the list of employees the framework builds an internal view object according to the association definition. However, there is a way to control how this view object is going to be created, for example we want to specify a desired sorting order or add an extra where clause to the VO query. We can tell the framework to use our custom view object definition instead of using a default one:

Having done that we have a full control on how the rows returning by the association accessor are going to be retrieved from the database.

That's it!

No comments:

Post a Comment

Post Comment