Finding Rows by Key

A key is a set of attributes that allow you to quickly retrieve one or more rows from a view object instance's query result. Persistent view object attributes based on primary keys are automatically part of the view object's key; you can make other attributes part of the view object's key as well.

At runtime, you can create a complete key (that is, a complete set of key values) to look up a single row, or a partial key to look up a set of rows.

To find rows by key:

  1. Create an array of Objects containing values for each part of the key. For example, supposr the view object custOrdVO has a key made up of Customer.CustomerId and Order.OrderId . To retrieve any row of custOrdVO having Customer ID 240 and Order ID 2440, you would use:
    Object[] custOrdKeyValues =
    {
      new Number(240),
      new Number(2440)
    };                

    To create a partial key, use null for one or more of the values. For example, to retrieve all rows of custOrdVO having Customer ID 240, you would use:

    Object[] custOrdKeyValues =
    {
      new Number(240),
      null
    };                
  2. Pass this array to the Key() constructor:

    Key custOrdKey = new Key(custOrdKeyValues);

  3. Pass this Key to findByKey() on the view object instance to retrieve an array of all rows that match the key. Also pass in the maximum number of rows to, or -1 to retrieve all matching rows:

    Row[] foundRows = custOrdVO.findByKey(custOrdKey, 5);

  4. To set the view object instance's current row pointer to one of the rows, pass the row to setCurrentRow() on the view object:

    custOrdVO.setCurrentRow(foundRows[0]);


Ways to Navigate Through Query Results
About Oracle ADF View Objects
Finding View Object Instances in the Data Model

 

 

 

Copyright © 1997, 2004, Oracle. All rights reserved.