Using View Criteria Programmatically
You also can create and use structured WHERE clauses programmatically. The example in the slide programmatically constructs view criteria that are similar to the view criteria constructed declaratively in the lesson titled “Declaratively Customizing Data Services.” The sample code does the following:
1. Instantiates the a ViewCriteria class by calling createViewCriteria() on the view object instance.
2. For each set of criteria that you need, create a view criteria row by calling createViewCriteriaRow() on the ViewCriteria.
3. Set the requirements for each view criteria row by calling setAttribute() on the ViewCriteriaRow. Pass to setAttribute() the name of the view object attribute and the SQL requirement to be applied to the attribute.
4. Add the rows to the view criteria by passing them to addElement() on the ViewCriteria.
5. Apply the view criteria to the view object instance by passing the ViewCriteria to applyViewCriteria().
6. Execute the query on the view object to return only the rows that satisfy all of the view criteria that you applied.