Saturday, May 15, 2010

Bit #18 - Dynamically changing the View Object's query WHERE clause

You can dynamically change the View Object's (VO) query WHERE clause by overriding the buildWhereClause() VO method. When doing so, ensure that you call the base class' buildWhereClause() first, to let the framework do its processing before making your own changes. The StringBuffer parameter that is passed to the method is the complete query SQL statement. Do your changes directly onto it. When done, make sure that you return appropriately a true/false boolean to indicate whether a WHERE clause was appended to the query or not. Here is an example.


    protected boolean buildWhereClause(StringBuffer sqlBuffer, int noBindVars) {

        // call ViewObjectImpl's buildWhereClause() to allow the framework to do its processing
        boolean hasWhereClause = super.buildWhereClause(sqlBuffer, noBindVars);

        if (hasWhereClause) { // framework added a WHERE clause
            // modify the WHERE clause as needed
        else { // framework did not add a WHERE clause, so we need to add it ourselves
            // add a WHERE clause here
            hasWhereClause = true; // ensure that is set to notify the framework

        return hasWhereClause; // return true/false to indicate whether a WHERE clause was added


View Object Implementation


  1. Thanks a lot for your post. It helped me a lot..

  2. I am using JDev Example Scenario : In my application, In the first page, I am choosing a location value. In the second page I have a model based VO. The where clause of the query has to be set dynamically, based on the location what I am choosing in the first page. How to achieve this?

  3. Have you looked at ExecuteWithParams?


Related Posts Plugin for WordPress, Blogger...