To define view criteria programmatically:
- VO must contain the attributes which are to be added in where clause.
- The following method is added in AMImpl java class & method is exposed via client interface.
import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewCriteriaItem;
import oracle.jbo.ViewCriteriaRow;
import oracle.jbo.domain.Number;
...
...
public void filterEmployees(){
ViewObjectImpl empVOImpl = getEmployeesView1();
ViewCriteria vc = empVOImpl.createViewCriteria();
ViewCriteriaRow vcr = vc.createViewCriteriaRow();
//criteria for employee id
ViewCriteriaItem vci1 = vcr.ensureCriteriaItem("JobId");
vci1.setValue("SH_CLERK");
//criteria for showing employees whose salary are more than 10000
ViewCriteriaItem vci2 = vcr.ensureCriteriaItem("Salary");
vci2.setOperator(">");
vci2.setValue(new Number(2500));
//criteria for department
int[] deptIds = {50,100};
ViewCriteriaItem vci3 = vcr.ensureCriteriaItem("DepartmentId");
vci3.setOperator("IN");
int i = 0;
for(int deptId: deptIds){
vci3.setValue(i++, new Number(deptId));
}
vc.addElement(vcr);
empVOImpl.applyViewCriteria(vc);
System.out.println("Query: " + empVOImpl.getQuery());
empVOImpl.executeQuery();
}
Above implementation is showing three conditions:
- Equal (JobId = "SH_CLERK")
- Greater than (Salary > 2500)
- IN (DepartmentId in (50,100))