Fun with ADF BC Bind Parameters – Part Three: Support for generic bind-parameters in ADF Business Components

0

It can easily be the case that in your ADF BC application many ViewObjects make use of the same bind-parameters, for example a bind parameter referring to the current user. One simple way of providing the correct value for such bind-parameters could be implementing a little piece of pre-query-trigger-like logic: by extending the ViewObjectImpl class with our own implementation and overriding the executeQueryForCollection() method, we can intercept default query processing and set the value of any generic bind-parameters just prior to query execution, if they have not already been set.

Typical examples of generic bind-parameters are :currentUser and :locale, but you can think up any parameters you like, ranging from user preferences to security considerations. We could even go so far as to have our executeForQueryCollection method inspect all bind parameters, and try to get values for any parameter still without value from a central method on the ApplicationModuleImpl.

The implementation of this mechanism is fairly simple:....

First we create a generic ViewObjectImpl class that we will use as the foundation for all our ViewObjects. The class itself is implemented like this:

package nl.amis.model.adfbc;<br /><br />import java.util.Locale;<br /><br />import oracle.jbo.server.ApplicationModuleImpl;<br />import oracle.jbo.server.ViewObjectImpl;<br /><br />public class GenericViewImpl extends ViewObjectImpl {<br />    public GenericViewImpl() {<br />    }<br /><br />    /**<br />        * Overridden method<br />        */<br />    protected void executeQueryForCollection(Object qc, Object[] params, <br />                                             int numberOfParams) {<br /><br />        Locale locale = getApplicationModule().getSession().getLocale();<br />        String currentUser = <br />            ((ApplicationModuleImpl)getApplicationModule()).getUserPrincipalName();<br />        applyGenericBindParam(params, &quot;language&quot;, locale.getLanguage());<br />        applyGenericBindParam(params, &quot;currentUser&quot;, currentUser);<br />        super.executeQueryForCollection(qc, params, numberOfParams);<br />    }<br /><br /><br />    /**<br />     * Looks in the params collection for a bind parameter with the indicated<br />     * name. If the parameter exists and it does not have a (non-default) value,<br />     * the paramValue is applied.<br />     *<br />     * @param params Collection of Bind Parameters (Where Clause Parameters)<br />     * @param paramName The name of the generic bind parameter whose value is to be applied<br />     * @param paramValue The value for the generic bind parameter under scrutiny<br />     */<br />    private void applyGenericBindParam(Object[] params, String paramName, <br />                                       Object paramValue) {<br />        for (int i = 0; i &lt; params.length; i++) {<br />            if (paramName.equalsIgnoreCase((String)((Object[])params[i])[0])) {<br />                // check for default value<br />                if ((&quot;xx&quot;.equalsIgnoreCase((String)((Object[])params[i])[1]))) {<br />                    // now apply the generic value <br />                    ((Object[])params[i])[1] = paramValue;<br />                }<br />            }<br />        }<br />    }<br /><br /><br />}<br />&nbsp;

Then we configure this class to be the generic superclass for all ViewObjects in our ADF BC project:

Now let’s create a ViewObject that makes use of the generic :language bind variable:

The bind variable is defined as follows:

When we create a simple straightforward ADF Faces application with a SelectOneChoice compont based on this JobsView, the content of the dropdownlist adapts to the language set in the browser running the web application. We do not need any additional configuration for this, as the ADF mechanics ensure that the browser locale is made available to the ADF BC Session object and we have just made sure with our generic ViewObjectImpl that any occurrence of the language bind parameter that still has the meaningless default value set has the current locale’s language set.

and in English:

Resources

JHeadstart Blog article on implementing horizontal authorization rules by adding filter conditions to the VO’s where-clause http://www.orablogs.com/jheadstart/howtos/HowToJ2EEAuthJHeadstart.htm#horizontal .

Steve Muench’s comparison between ADF BC framework methods and Oracle Forms trigger logic: http://www.oracle.com/technology/products/jdev/tips/muench/formstriggers/index.html#queryprocessing .

List of commonly used methods in ADF BC framework: http://www.oracle.com/technology/products/jdev/tips/muench/mostcommon/index.html#businesstiervo .

 

 

Share.

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director for Fusion Middleware. Consultant, trainer and instructor on diverse areas including Oracle Database (SQL & PLSQL), Service Oriented Architecture, BPM, ADF, Java in various shapes and forms and many other things. Author of the Oracle Press book: Oracle SOA Suite 11g Handbook. Frequent presenter on conferences such as JavaOne, Oracle OpenWorld, ODTUG Kaleidoscope, Devoxx and OBUG. Presenter for Oracle University Celebrity specials.

Comments are closed.