Friday, September 19, 2014

ADF - View Link Accessor Type and Cardinality

A view link associates two view objects to form a master-detail relationship. A view link accessor specifies an accessor attribute by which a view row at one end of a master-detail relationship specified by a view link can access the related view row or rows at the other end of the relationship. When you select to generate the custom view row class for the view object with an accessor, JDeveloper will uses the accessor's name to generate the corresponding view link accessor method, a getter method in the view row class.

By default, JDeveloper generates the view link accessor type and the corresponding view link accessor method return type with respect to the cardinality of the view link. For a "many" side of a view link, the view link accessor type will be "oracle.jbo.RowIterator"; for a "one" side, the view link accessor will have the type of "oracle.jbo.Row". This default behavior is acceptable in a majority of cases. For example:

View Object: DepartmentView

  <ViewLinkAccessor
    Name="EmployeesView"
    ViewLink="model.views.links.EmpToDeptLink"
    Type="oracle.jbo.RowIterator"
    IsUpdateable="false"/>

View Object: EmployeeView

  <ViewLinkAccessor
    Name="DepartmentView"
    ViewLink="model.views.links.EmpToDeptLink"
    Type="oracle.jbo.Row"
    IsUpdateable="false"/>

Sometimes, you may want to change this default behavior. In my case, I have a one-to-one master-detail composition relationship between UserView and ContactInfoView. For a new user, once a new user view row is created, a linked contact information view row is required to be created. In the UserView, the view link accessor for the ContactInfoView is defined by default as the following:

  <ViewLinkAccessor
    Name="ContactInfoView"
    ViewLink="model.views.links.UserToContactInfoLink"
    Type="oracle.jbo.Row"
    IsUpdateable="false"/>

I want the view link accessor type to be "oracle.jbo.RowIterator", so that from the user view row, I can use the accessor to create the associated contact information view row.

Fortunately, we can manually change the accessor type from "oracle.jbo.Row" to "oracle.jbo.RowIterator" in the source code of the view object:

View Object: UserView

  <ViewLinkAccessor
    Name="ContactInfoView"
    ViewLink="model.views.links.UserToContactInfoLink"
    Type="oracle.jbo.RowIterator"
    IsUpdateable="false"/>

In case you have already generated the custom view row class, you can manually fix the return type of the view link accessor method.

Now, with this view accessor, I can create contact information view row from a user view row with the code like this:

  userViewRow.getContactInfoView().createRow();


1 comment:

  1. That's a good post to write, I used to do the same for adding new view objects to oracle rule file when relating objects to make long chains of view objects.

    ReplyDelete