Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

createRow() while looping through RowSetIterator

Ray KellyMay 14 2019 — edited May 20 2019

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?

Comments
Post Details
Added on May 14 2019
13 comments
825 views