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

Post a Comment