Pages

Saturday, December 18, 2010

Use SQL subquery and SQL OPERATOR ( IN, BETWEEN) in ViewCriteria

Use SQL subquery and SQL OPERATOR ( IN, BETWEEN) in ViewCriteria


This post will illustrate how to use IN,BETWEEN operators in ViewCriteria. How to use the SQL subquery with ViewCriteria.

In this application, HRAppModuleImpl.java contains a method applyCustomCriteria() with three input parameters - departmentIdVar, lowSalaryVar, and highSalaryVar. Expose this method and test .
Below steps explains the code in snapshot below-
1.Create ViewCriteria using createViewCriteria().
2.Create ViewCriteriaRow using createViewCriteriaRow().
3.Create String with required where Clause.
4.Create ViewCriteriaItem  using ensureCriteriaItem. 
5.Use setOperator() to set the sqlOperator. Use JboCompOper. class to find list of supported operators.
6.Use setValue() method of ViewCriteriaItem to set value . Incase of IN/BETWEEN operator, add multiple values. For sql subquery for IN operator, simply use setValue.
8.Use addElement method to ViewCriteriaRow to VC.
9.Use applyViewCriteria to apply created viewCriteria.






 Expose Method -



Run AM and pass parameters to method -

Project can be downloaded from here.