Tuesday, 19 April 2016

Define WHERE Clause on dynamic ViewObject created on the fly


We all know there are different ways to define WHERE clause on a viewObject at runtime and previously I have posted about it
Check -

ADF Basics: Apply and Change WHERE Clause of ViewObject at runtime programmatically
ADF Baiscs: Define and remove named bind variable in viewObject at runtime programmatically
Setting view object bind variable (Override bindParametersForCollection, prepareRowSetForQuery, executeQueryForCollection )

This post is about defining WHERE Clause on dynamic viewObject created at run time using SQL query

So for this created a dummy view object using dual

SELECT * FROM DUAL


Now remove this dummy viewObject and create new ViewObject with same name using query

        //Get dummy viewObject
        ViewObject dynVo = this.getdynamic1();
        //Remove viewObject from Application Module
        dynVo.remove();
        //Creates a read-only View Object, given a query statement and a name for the View Object.
        this.createViewObjectFromQueryStmt("dynamic1", "SELECT * FROM DEPARTMENTS");

There is no difference in syntax of setWhereClause method but here we pass JDBC Positional bind variable using "?" symbol



        //Apply desired WHERE Clause and declare bind variable
        dynVo.setWhereClause("DEPARTMENT_NAME=?");

        //Pass Bind Variable value using index
        dynVo.setWhereClauseParam(0, "Finance");

        // Execute ViewObject to finally apply where clause
        dynVo.executeQuery();

This is how we can apply WHERE clause on dynamic viewObjects
Cheers :) Happy Learning

No comments:

Post a Comment