navigation

SQLBuilder Configuration (Configure JDeveloper to work with MS SQL Server)

SQLBuilder Configuration (Configure JDeveloper to work with MS SQL Server)

This blog post is written to show how we can solve errors with SQLBuilder in ADF application on JDeveloper and WebLogic Server (the example uses MS SQL Server for a database). These errors usually appear when we use a database different from the Oracle Databases. For example:

 

To solve this issue we need to do two simple things – create a listener-class (InitializationListener) and register a listener for this class in the web.xml file. Here`s how the solution is describes in the Oracle’s documentation.

Configure Runtime SQL Generation

Before running your application, you must specify a system property to generate the correct flavor of SQL at runtime. You do this by specifying jbo.SQLBuilder as a system property with the correct value for the database you are using. See the following table: 

Database Value of jbo.SQLBuilder
SQL Server SQLServer
DB2 DB2
Other databases (MySQL, Sybase, etc) SQL92

You can specify the system property as an operating system environment variable or Java command line option, but the recommended approach is to set up a web application filter, using the steps below.

1. Create a Servlet Context Listener

Create a new class in your application and add code to set the jbo.SQLBuilder property to the correct value for your database. This example is for SQL Server:

package myproject.common; // Substitute your package name

import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import oracle.jbo.common.PropertyMetadata;

public class InitializationListener implements ServletContextListener {

    private ServletContext context = null;

    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        AccessController.doPrivileged(new
            PrivilegedAction() {
                public Object run() {
                    // Set the SQL Builder to the correct value for your database, SQL Server in this example.
                    System.setProperty(PropertyMetadata.PN_SQLBUILDERIMPL.getName(),
                                       "SQLServer");
                    return null;
                }
            });
    }

    public void contextDestroyed(ServletContextEvent event) {
        context = event.getServletContext();
    }
}

2. Set up a Web Application Filter Edit your application’s web.xml file and add <listener> tags containing your servlet context listener class. This causes your listener to be executed every time the application starts up.

<listener>
    <listener-class>myproject.common.InitializationListener</listener-class>
</listener>

 

Note: The application module’s configuration has ajbo.SQLBuilder property, but setting it has no effect. See the topic below.

jbo.sqlbuilder property as an application module configuration option fails (9018765)
An ADF application module configuration (bc4j.xcfg file) can define a database connection other than Oracle database type, such as SQLServer, IBM DB2, or MySQL. By default the SQL style will be “Oracle” for all database connections and should be modified to manually override the SQL style with one that supports the chosen database vendor. The bc4j.xcfg file provides thejbo.SQLBuilder property for this purpose, but the property is ignored and CRUD operations performed on the application module will result in the exception:

The workaround is to specify jbo.SQLBuilder as a system property instead of an application module configuration option. This will cause the application module to pick up the value from the system properties instead of using the default value (Oracle). However, specifying the system property as an  OS environment  variable or Java command line option comes with high administration overhead. The best solution is to set up a web application filter in the web.xml deployment descriptor and define the system property there. For example, the servlet context listener in the following sample will set the system property for the web application.

import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import oracle.jbo.common.PropertyMetadata;

public class InitializationListener implements ServletContextListener {
        private ServletContext context = null;

                public void contextInitialized(ServletContextEvent event) {
                        context = event.getServletContext();

                        AccessController.doPrivileged(
                                new PrivilegedAction() {
                                        public Object run() {
                                                System.setProperty(PropertyMetadata.PN_SQLBUILDERIMPL.getName(), "SQLServer");
                                                        return null;
                                        }
                                });
                }

                public void contextDestroyed(ServletContextEvent event) {
                        context = event.getServletContext();
        }
}

 

* You can check the SQL Flavor and Type Map opening project properties and navigate to the Business Components.

BOBI image 1

 

Useful resources:

http://www.oracle.com/technetwork/developer-tools/jdev/multidatabaseapp-085183.html

http://www.oracle.com/technetwork/developer-tools/jdev/knownissues-097654.html#bc3

 

What is your usual approach, share in the comments below.

Boris Velichkov

Java EE and Oracle Developer

More Posts - Website

Follow Me:
TwitterLinkedIn

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!