Tuesday, June 26, 2012

Applying multiple VCs to a ViewObject


  1. EmployeesVO.
  2. Two Design Time VCs
  3. findByName->( (UPPER(Employees.FIRST_NAME) LIKE UPPER('%' || :bName || '%') ) )
  4. findByEmail -> ( (UPPER(Employees.Email) LIKE UPPER('%' || :bEmail || '%') ) )
  5. Apply these 2 VCs programmatically with an AND Condition.




    public void applyMultipleVCs(String bName, String bEmail) {
        ViewObjectImpl viewObj = getEmployeesVO1();
        if (viewObj != null) {
            ViewCriteria vc =
                viewObj.getViewCriteria("findByName");
            viewObj.setNamedWhereClauseParam("bName", bName);
            ViewCriteria vc1 =
                viewObj.getViewCriteria("findByEmail");
            viewObj.setNamedWhereClauseParam("bEmail", bEmail);
            viewObj.applyViewCriteria(vc,true);
            viewObj.executeQuery();
           
            viewObj.applyViewCriteria(vc1,true);
            viewObj.executeQuery();
            viewObj.removeApplyViewCriteriaName("findByName");
            viewObj.removeApplyViewCriteriaName("findByEmail");
            viewObj.setRangeSize(-1);
            Row[] allRows = viewObj.getAllRowsInRange();
            for(Row row : allRows){
                String firstName = (String)row.getAttribute("FirstName");
                String email = (String)row.getAttribute("Email");
                System.err.println("-->"+firstName+"        ---->"+email);
            }
               
        }
    }