Skip to main content

Customizing the SQL Builder Class

Sometimes you might want to add some special treatment for specific types when framework generates JDBC statements for Create, Read, Update or Delete. ADF let you to add your own custom SQL builder class for an application module through jbo.SQLBuilderClass parameter that you configure in bc4j.xcfg file. To do so, you must set jbo.SQLBuilder="Custom" and then specify fully qualified name of your class as parameter to jbo.SQLBuilderClass in bc4j.xcfg file. Hers is an example:

 <AppModuleConfig DeployPlatform="LOCAL"   
     jbo.project="model.demo.DemoModel" name="AppModuleAMLocal"  
     ApplicationName="model.demo.AppModuleAM">  
      <Database   
        jbo.SQLBuilder="Custom"  
        jbo.SQLBuilderClass="framework.bc.extension.OracleSQLBuilderImplEx"   
       jbo.locking.mode="optimistic"/>  
       <Security AppModuleJndiName="model.demo.AppModuleAM"/>  
       <Custom JDBCDataSource="java:comp/env/jdbc/HRDS"/>  
  </AppModuleConfig>  

Your SQL builder class needs to be extended from oracle.jbo.server.OracleSQLBuilderImpl or oracle.jbo.server.BaseSQLBuilderImpl(or a fresh implementation of oracle.jbo.server.SQLBuilder interface if you want to start from scratch). Also there should be public static SQLBuilder getInterface() method defined in your class to return a singleton instance of it. Then, you can override the methods of your choice based on use cases. Here is an example:

 public class OracleSQLBuilderImplEx extends OracleSQLBuilderImpl {  
   private static SQLBuilder mSQLBuilderInterface = null;  
   public OracleSQLBuilderImplEx() {  
     super();    
   }  
   /**  
    * Gets the singleton instance of this class.  
    * This is required by the framework in order  
    * to override the default SQLBuilder  
    * @return a <tt>SQLBuilder</tt> object.  
    */  
   public static SQLBuilder getInterface() {  
     if (mSQLBuilderInterface == null) {  
       if (Diagnostic.isOn()) {  
         Diagnostic.println("OracleSQLBuilder reached getInterface");  
       }  
       mSQLBuilderInterface = (SQLBuilder)(new OracleSQLBuilderImplEx());  
       if (Diagnostic.isOn()) {  
         Diagnostic.println(mSQLBuilderInterface.getVersion());  
       }  
     }  
     return mSQLBuilderInterface;  
   }  
      //Other methods go here  
 }  

Comments

Dinil Mithra said…
A must read post ......

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…

Happy New Year 2018 !

We can't go back and change the beginning, but we always can start where we are and change the ending. Believe in yourself and you will be unstoppable!

Wishing you and your family a very happy new year 2018 !!!