Sunday, May 2, 2010

Bit #15 - Using a Key to locate a Row in a View Object, Pt. 2

Instead of using the findByKey() method to locate a number of rows in the View Object identified by a Key attribute - explained in Bit #14 - Using a Key to locate a Row in a View Object, you can use the View Object getRow() method supplying the Key as an argument. This method will return the Row identified by the Key supplied as an argument to it. An example follows.

Example:

    // in the context of the ApplModuleImpl

    // locate the employee's department
    Number departmentId =
        ((EmployeesRowImpl)(this.getEmployees().getCurrentRow())).getDepartmentId();
    Key keyDepartment = new Key(new Object[] { departmentId });

    // get the department based on the department identifier
    DepartmentsRowImpl department =
        (DepartmentsRowImpl)this.getDepartments().getRow(keyDepartment);

    if (department != null) {
        // you can access the Department's attributes here....
    }



Context:

Application Module Implementation Class
View Object Implementation Class

2 comments:

  1. Although it's more comfortable to use the getRow method instead of the findByKey one because of the array stuff, I think it worths pointing out that findByKey is better in performance than getRow. You can read it here:

    http://download.oracle.com/docs/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#getRow_oracle_jbo_Key_

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...