Monday, May 24, 2010

ViewCriteria in Shared AM-Reuse BindVariable and QueryCollection from Cache

A VO on a sharedAM caches multiple rowsets by the bind variables. So if you query a VO 5 times with 5 different bind variables, it does cache 5 rowsets. And if you go back and requery by those same bind variables you dont not see any database I/O

Here is a sample code

    public void applyVC() {
EmpVOImpl vo = this.getEmpVO1();

ViewCriteria vc = vo.getViewCriteria("findByEmpId");
vo.setNamedWhereClauseParam("pEmpId", "931");
vo.refreshCollection(null, true, true);

int rowcount = 0;
while (vo.hasNext()) {
Row row =;
System.out.println("Total # of rows = " + rowcount);


Execute this multiple times from AM tester or from ADF UI and you will see the difference.

Important note is,instead of executeQuery() you should use refreshFromCollection() so that the Rowset is resued from QueryCollection cache.

Technical Analysis
For SharedAM,Once the RowSet is closed, the QueryCollection will be released to the QueryCollection cache and potentially reused upon the next request.

No comments: