"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
|