Wednesday, 3 September 2014

multiple master - one detail relationship in BC4J

In most of the cases the real life structures can be simplified to one master with 0 to N details. Each detail can be a treated as a master to other details. But there are cases when the cardinality changes 180 degrees. For the first time it sounds strange to have multiple master tables that influences on the detail one but... think about plane flights. The requirement is to display two lists of airports and display flights between them. For performance point of view destination list will be dependent on the departure one. Another example, we would like to filter employees basing on both departments and jobs lists simultanously. Lookups and employees should be displayed as tables. Is it possible in ADF? It is, and it doesn't need a lot of coding! I belive you've already got HR example scheme with you.

We need to have view objects departments, jobs and employees tables (read only will be enough). Also there should be view links between them (on EMP_DEPT_FK and EMP_JOB_FK foreign keys). Model project structure should be similar to this:


Now let us focus more on Application Module Data Model definition. Please click on DepartmentsView and rename New View Instance to Departments and move it right.


Select EmployeesView via EmpDeptFkLink, rename it to Employees and move it as detail of Depatrments instance.


Select JobsView, rename it to Jobs and move it to the right. Now please select EmployeesView via EmpJobFkLink and rename it, the tricky part, to Employees.



An error? Not exactly, it will be the same instance for both Jobs and Departments. So, please click Yes. Data Model and AppModuleDataControl should look like this:



Last thing to do is to prepare test page for it. Please expand Departments node in the AppModuleDataControl, select Employees iterator and drag it to the test page as ADF Master Table, Detail Table.


Then drag and drop Jobs iterator on the test page. Select table with employees and add partial trigger to the Jobs table (partial trigger to Departments table should already be there). My page structure after simple layout rework is:


And if somebody is interested in the page definition:



The running example:


4 comments:

  1. Hi Kamil, i don't understand how create the same instance in jdev 12.1.3, because is different version, can you help me.
    Thanks a lot.
    Giovanni

    ReplyDelete
    Replies
    1. @giovanni
      Second view object instance will be called EmployeesView1. Please go to the source of application module and remove tag. After that please search for the EmployeesView1 string and rename it to Employees. It should be found only in tag. If you've got java implementation of application module, client interfaces and so on you'll need to synchronize them with the xml file.

      Delete
    2. Nevertheless I'll try to find better, declarative solution for that :)

      Delete