Wednesday, January 18, 2012

In-Memory Filtering Without Affecting Default Row Set

Noticed the following requirement (multiple times) while working with ADF developers - Find out rows in the default row set that meets specific conditions - In other words, perform in-memory filtering without affecting the primary row set.
By default, when you apply in-memory filtering  using ViewCriteria or RowMatch, they are applied on default row set.The following code snippet may help you to perform in memory filtering without affecting your default row set-
 CountriesViewImpl countriesViewImpl = (CountriesViewImpl)getCountriesView1();  
 countriesViewImpl.executeQuery();  
 //Define VC for in-memroy filtering  
 ViewCriteria vc = countriesViewImpl.createViewCriteria();  
 vc.setCriteriaMode(ViewCriteria.CRITERIA_MODE_CACHE);  
 ViewCriteriaRow vcr1 = vc.createViewCriteriaRow();  
 vcr1.setAttribute("CountryName", "LIKE A%");  
 vc.add(vcr1);  
 //Override 'protected' findByViewCriteriaForViewRowSet in CountriesViewImpl  
 //and mark it as 'public' so that client can call this API  
 RowIterator rowIter =  
      countriesViewImpl.findByViewCriteriaForViewRowSet(getCountriesView1().getDefaultRowSet(), vc, 50,  
                                                                   ViewObject.QUERY_MODE_SCAN_VIEW_ROWS, null, null);  
 while(rowIter.hasNext()){  
   Row row=rowIter.next();  
      //Work with filterered rows  
 }  



0 comments: