Using JDeveloper 12.2.1.3
I am calling a method from my AMImpl class that iterates over the rows in my VO.
The method makes a copy of the row being iterated over.
Let's say I have 2 rows in my VO.
When I enter the while (rsi.hasNext()) loop for the first time, my rsi.rowCount is 2.
Inside the loop, I am using the createRow() method to create a copy of the existing row.
As soon as I set one of the fields in the new row, the RowSetIterator that I am currently looping through includes the new row (rowCount is now 3).
This is causing unpredictable results.
Here is my current code:
public void setCodedFields() {
RowSetIterator rsi = this.createRowSetIterator(null);
rsi.reset();
TestViewRowImpl row = null;
TestViewRowImpl newRow = null;
while (rsi.hasNext()) {
row = (TestViewRowImpl) rsi.next();
if (row.getFieldC() == null) {
row.setFieldC("ABC");
} else {
System.out.println("+++++++++++++++++ ROW SET ITERATOR COUNT 1 = " + rsi.getRowCount());
TestViewRowImpl newRow = (TestViewRowImpl) createRow();
System.out.println("+++++++++++++++++ ROW SET ITERATOR COUNT 2 = " + rsi.getRowCount());
newRow = (TestViewRowImpl) createRow();
System.out.println("+++++++++++++++++ ROW SET ITERATOR COUNT 3 = " + rsi.getRowCount());
newRow.setFieldA(row.getFieldA());
newRow.setFieldB(row.getFieldB());
newRow.setFieldC(row.getFieldC());
System.out.println("+++++++++++++++++ ROW SET ITERATOR COUNT 4 = " + rsi.getRowCount());
insertRow(newRow);
}
}
rsi.closeRowSetIterator();
rsi = null;
}
The code above will generate the following output (assuming 2 records initially):
+++++++++++++++++ ROW SET ITERATOR COUNT 1 = 2
+++++++++++++++++ ROW SET ITERATOR COUNT 2 = 2
+++++++++++++++++ ROW SET ITERATOR COUNT 3 = 2
+++++++++++++++++ ROW SET ITERATOR COUNT 4 = 3
+++++++++++++++++ ROW SET ITERATOR COUNT 1 = 3
+++++++++++++++++ ROW SET ITERATOR COUNT 2 = 3
+++++++++++++++++ ROW SET ITERATOR COUNT 3 = 3
+++++++++++++++++ ROW SET ITERATOR COUNT 4 = 4
Is there a better way to copy the row based on the value of a field in the original row?