Wednesday, December 5, 2012

Do you know what is a Composite View Object?

Oracle ADF Business Component stack offers something known as composite view object.Did you know that? The composite view objects help you to combine hierarchical results from two or more master detail view objects linked through a view link into a single composite view with flattened query retrieving the same result set.

For example, consider the Department and Employee hierarchies built using the Department and Employee view objects, linked through a view link. You can build a composite view object at runtime by combining these two view objects as shown in the following code snippet. This feature is explained in the Appendix of the book Oracle ADF Real World Developer’s Guide. You are free to download the Appendix from packtpub site. Yes, its absolutely free !!!

 //In application module implementation class   
  public void createCompositeDeptEmpVO() {  
     ViewDefImpl compVODef = (ViewDefImpl)createCompositeViewDef("DeptEmpDetail", "DeptEmpDetail");  
     compVODef.addViewUsage("Dept", "sample.adfguide.model.DepartmentVO");  
     compVODef.addViewUsage("Emp", "sample.adfguide.model.EmployeeVO",  
                 "sample.adfguide.model.DeptToEmpViewLink", "EmployeeVO", "Dept");  
     compVODef.addAllRowAttributes("Dept");  
     compVODef.addRowAttribute("EmployeeId", "Emp", "EmployeeId");  
     compVODef.addRowAttribute("FirstName", "Emp", "FirstName");  
     compVODef.addRowAttribute("LastName", "Emp", "LastName");  
     compVODef.addRowAttribute("EmpDepartmentId", "Emp", "DepartmentId");  
     compVODef.addRowAttribute("HireDate", "Emp", "HireDate");  
     ViewCriteria vc = compVODef.createViewCriteria();  
     ViewCriteriaRow vcr = vc.createViewCriteriaRow();  
     ViewCriteriaItem vcItem = vcr.ensureCriteriaItem("HireDate");  
     vcItem.setOperator(">=");  
     vcItem.setValue("2008-02-13");  
     vc.add(vcr);  
     compVODef.putViewCriteria("DeptEmpDetailVC", vc);  
     compVODef.setOrderByClause("DepartmentName, FirstName");  
     compVODef.resolveDefObject();  
     compVODef.writeXMLContents();  
     compVODef.saveXMLContents();  
     ViewObjectImpl compDeptEmpVO = (ViewObjectImpl)createViewObject("DeptEmpDetail", compVODef.getFullName());  
     compDeptEmpVO.getViewCriteriaManager().setApplyViewCriteriaName("DeptEmpDetailVC");  
     // If needed, retrieve the composite VO SQL statement  
     String sqlQueryStmt = compDeptEmpVO.getQuery();  
     System.out.println("sqlQueryStmt -" + sqlQueryStmt);  
     // If you want the data, iterate it like a normal view object.  
     compDeptEmpVO.setForwardOnly(true);  
     compDeptEmpVO.executeQuery();  
     while (compDeptEmpVO.hasNext()) {  
       Row r = compDeptEmpVO.next();  
       System.out.println(r.getAttribute(0) + "-" + r.getAttribute(5));  
       // Process current row in whatever way is needed  
     }  
   }  

Well there many interesting stuff like this.
To learn more, you can download the Appendix of my book Oracle ADF Real World Developer’s Guide. This is absolutely free :)

Following are covered in the Appendix-
  • Life-cycle of an ADF Fusion web page with region 
  • Transaction management in Fusion web applications 
  • Building a dynamic model-driven UI with ADF 
  • Building composite view objects 
  • Building application modules with no database connection 
  • Looking up the UI component from the component tree at runtime 
Download

To download the Appendix, click here

Enjoy!!!

1 comment:

Siva said...

Hi Jobinesh,

Very useful post.

Thanks!