Dive into Oracle ADF

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 8:13:28 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Search blog with Google:
 

Search BC4J JavaDoc:
 

August 2003
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Jul   Sep

Get Firefox!

Thursday, August 07, 2003

Fellow JDeveloper team member Brian Duff kicks off his shiny new blog with an article about Finding Memory Leaks with JDeveloper's Debugger.
5:02:06 PM    



"How can I clone the current row in a view object?"

I cobbled together the following helper method that shows how to achieve this. It basically just uses the runtime metadata that you can get about the row structure (StructureDef) to then iterate over the attributes of the current row can copy the current values into the new row for any attributes that are not part of the primary key. This assumes that either the primary key will be getting defaulted already by underlying entity objects participating in the view, or that the client will set appropriate values for the new row's primary key attributes.

public class Helper  {
  /*
   * Clones all of the non-primary-key attributes from the current
   * row in a rowset, and returns the new row. Note that since
   * the oracle.jbo.ViewObject interface extends oracle.jbo.RowSet
   * (and delegates the methods of RowSet to its built-in "Default Rowset",
   * you can also pass in a ViewObject, too.
   */
  public static Row cloneNonPKAttrsFromCurrentRow(RowSet rs) {
    Row currentRow = rs.getCurrentRow();
    Row newRow = rs.createRow();
    StructureDef def = newRow.getStructureDef();
    AttributeDef[] attrs = def.getAttributeDefs();
    for (int j=0, numAttrs = attrs.length; j < numAttrs; j++) {
      if (!attrs[j].isPrimaryKey()) {
        newRow.setAttribute(j,currentRow.getAttribute(j));
      }
    }
    /*
     * If you want the cloned row to be considered just a blank
     * row with default values until at least one more user-supplied
     * value is set, then you could add the additional line here:
     *
     * newRow.setNewRowState(Row.STATUS_INITIALIZED);
     *
     * before returning it.
     */
    return newRow;
  }

8:38:05 AM    


© Copyright 2008 Steve Muench.