Wednesday, January 7, 2015

RowSetIterator next never returns null, causing infinite loop

The recommended way of using "RowSetIterator" for a view object:

Always create a "Secondary Row Set Iterator" and close it when finished.
Do not use getRowSetIterator() as it impacts row currency on the front end so firstly you should use createRowSetIterator and you should call closeRowSetIterator on the iterator created through this because if you don't, framework will create new ViewRowSetIteratorImpl instances and keep on adding them.

Code example:
DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
EmpVOImpl empVoImpl=(EmpVOImpl)bc.findIteratorBinding("EmpVO1Iterator").getViewObject();
    
RowSetIterator it = empVoImpl.createRowSetIterator(null);
while(it.hasNext()){
    EmpVORowImpl row=(EmpVORowImpl)it.next();
    if(row.getSal()!=null){
        totalAmount=row.getSal().add(totalAmount);
    }
}
it.closeRowSetIterator();
If necessary, use finally block

           try{
               while(it.hasNext()){
            EmpVORowImpl row=(EmpVORowImpl)it.next();
            if(row.getSal()!=null){ 
                  totalAmount=row.getSal().add(totalAmount);
            }
        }
} catch(Exception e) {
              //handle here
} finally {
      it.closeRowSetIterator();
}

Please refer to the links below for the issue:
https://community.oracle.com/thread/2242010
http://ramannanda.blogspot.ca/2013/04/adf-examining-memory-leaks.html
http://adfbugs.blogspot.ca/2009/07/iterating-through-view-object.html

https://community.oracle.com/message/12788828#12788828


No comments:

Post a Comment