Programatically Applying and Creating View Criteria

CASE 1: I have already created a view criteria in EmployeeVO, and I want to call it programmatically.

public void searchEmployee(Number employeeId) {
   ViewObjectImpl vo = getEmployeesView1();
   ViewCriteria vc = vo.getViewCriteria("findEmployeeVC");
   vo.applyViewCriteria(vc);
   vo.setNamedWhereClauseParam("pEmployeeId", employeeId);
   vo.executeQuery();
}

CASE 2: I want to create a view criteria dynamically and execute it programmatically.

public void searchByEmployeeIdEmail(Number employeeId, String email) {
   ViewObjectImpl vo = getEmployeesView2();
   ViewCriteria vc = vo.createViewCriteria();
   ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
   vcRow.setAttribute("EmployeeId", employeeId);
   vc.addRow(vcRow);
   vcRow.setAttribute("Email", email);
   vc.addRow(vcRow);
   vo.applyViewCriteria(vc);
   vo.executeQuery();
}

This is a helper method

    public static void createAndExecuteViewCriteria(ViewObject vo, String attributeName, Long      attributeValue) {
        ViewCriteria  vc = vo.createViewCriteria();
        ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
        vcRow.setAttribute(attributeName, attributeValue);
        vc.addRow(vcRow);
        vo.applyViewCriteria(vc);
        vo.executeQuery();
    }

Comments

Popular posts from this blog

Another user has changed the row with primary key oracle.jbo.Key[12 ].

Working With File Throgh WebUtill

weblogic windows JPS-01050: Opening of wallet based credential store failed. Reason java.io.IOException: Failed to lock cwallet.sso.lck