Skip Headers
Oracle® Application Development Framework Developer's Guide For Forms/4GL Developers
10g (10.1.3.1.0)

Part Number B25947-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

9.7 How to Access Related Entity Rows Using Association Accessors

Often your validation rules or programmatic defaulting of derived values may require consulting the values of associated entity rows. The association accessor methods in your entity object custom Java class make this task extremely easy. By calling the accessor method, you can easily access any related entity row — or RowSet of entity rows — depending on the cardinality of the association.

Example 9-10 shows an example of programmatic defaulting logic in use in the SRDemo application's ServiceHistory entity object. The line number of the new service history row is calculated by accessing the containing parent entity row of type ServiceHistoryImpl, and invoking a helper method called getMaxHistoryLineNumber() on it, before incrementing that value by one. If the parent entity row is already in the cache, the association accessor accesses the row from there. If not, it is brought into the cache using the primary key.

Example 9-10 Accessing Composing Parent Entity Row In a Create Method

// In ServiceHistoryImpl.java in SRDemo sample
protected void create(AttributeList nameValuePair) {
  super.create(nameValuePair);
  setSvhType(getDefaultNoteType());
  setCreatedBy(getCurrentUserId());
  setLineNo(new Number(getServiceRequest().getMaxHistoryLineNumber()+1));
}

Example 9-11 illustrates the code for the getMaxHistoryLineNumber() in the ServiceRequest entity object's custom Java class. It shows another use of an association accessor to retrieve the RowSet of children ServiceHistory rows (of type ServiceHistoryImpl) in order to calculate the maximum value of the LineNo attributes in the existing service history rows.

Example 9-11 Accessing Composed Children Entity Rows in a Calculation Using Association Accessor

// In ServiceRequestImpl.java in SRDemo Sample
public long getMaxHistoryLineNumber() {
  long max = 0;
  RowSet histories = (RowSet)getServiceHistories();
  if (histories != null) {
    while (histories.hasNext()) {
      long curLine = ((ServiceHistoryImpl)histories.next()).getLineNo()
                                                           .longValue();
      if (curLine > max) {
        max = curLine;
      }
    }
  }
  histories.closeRowSet();
  return max;
}