Open Source Software · Technology

Oracle Weblogic ADF – Application Module Datasource Connection


For a good idea about JDBC URL vs JDBC Datasource see:  http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcservices.htm#ADFFD1501

Configuring JDBC Datasource

According to Oracle “A data source is a vendor-independent encapsulation of a database server connection”.

When deploying an Oracle ADF application with a bc4j (Business Configuration) to a stand-alone Weblogic instance, you need to make sure your data-source is configured in your application and defined in your weblogic server.

FYI: The  “embedded” Weblogic Server (WLS) is the one that comes with JDeveloper i.e. the one that runs when you right click on a JSF page and click the play-button.  The “Stand-alone” Weblogic Server is something that you installed. So if you did not download Weblogic you can follow these links: [download from here ] and [install doc is here].

Once you have the stand-alone weblogic server up and running and have a database instance to connect to, go to the weblogic admin console http://<server-host&gt;:<server-port>/console and enter the admin login/password.  The default is “weblogic” and the password you supplied during the install process.

In the Weblogic admin console look at the menu items on the left side of the screen and under “Domain Structure” menu goto the “Services” node, expand it and then goto the “JDBC” node and expand that.  Click on the “Data Sources” child node of JDBC and you can see the configured data sources.  For example: In the image below you are seeing the datasources for my soa1_server WLS managed server instance and it has quite a few datasources configured.

Configuring Weblogic  Standalone server:

Steps to create a new data source are listed in the “Gallery” below … you need to go to through the Weblogic Wizard and enter your Database Url/Port.

Configuring the ADF Application:

Now you need to configure your ADF application to use this otherwise you may see errors like “password: null” etc. They are really vague messages but the stack trace tells the story – the Faces context tries to load the BC and the config cannot connect to a database because of missing or invalid connection properties.

Here are the steps for configuring your JDev Application … start with opening your Application Module XML (the Oracle editor for the XML opens up), select the “Configuration” tab and then set your datasource name there.

Advertisements

7 thoughts on “Oracle Weblogic ADF – Application Module Datasource Connection

  1. Hi ! Thanks for the blog.
    I have recently created the datasource for the custom application and it’s working good. But is there a way to use the connections.xml itself in the standalone weblogic server and run the application ? I have reconfirmed that the .ear has the connections.xml.

    Thanks in Advance,
    Arun

    1. Arun,
      The key difference is between using a JDBC URL vs JDBC datasource. I believe the URL definitions are stored in the connection.xml and the ear has it if you have configured your AM to use the JDBC url. ( Look at the documentation here http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcservices.htm#ADFFD1501 )

      It says … ” You can use either the JDBC URL and the JDBC data source connection type to run the application module in any context where Java can run. Your application is not restricted to running inside a Java Enterprise Edition (Java EE) application server…” and adds “The JDBC data source offers advantages that the JDBC URL connection type does not. When you define a connection type based on a data source, you reconfigure the data source without changing the deployed application. The data source is also centrally defined at the application server level, whereas JDBC URL connections are not.

      So using a JDBC URL means you cannot configure it at the server level and need to redeploy your app, each time you need to change something. Either that, or if you can stop your server, unpackage the ear, change the connections.xml and repackage the ear and reinstall and bounce : ) – Easier just to use a datasource.

      cheers
      Alok

      1. I still don’t think you answer the question. The question is how can you make sure the WLS use database url, not the datasource if both are defined?
        Which one will be picked first and are both will be looked and try to get connections?
        Arun

      2. Arun,
        So the easy answer is to specify the configuration name when instantiating the AM using Configuration.createRootApplicationModule(AMName, Config)

        I guess for the UI stuff, the famework relies on the default configuration when binding to the datacontrols, I am just starting to play in that space. For back-end services, like webservice or JMS invocations to an AM you can instantiate the application module using the Configuration class and select at runtime.

        Go to your Application Module (double click on open) -> click on Configurations … by default you will see two configurations – Shared and Local. One of these is selected as default. Now, open one of these …say Shared and have it use a datasource instead of a JDBC url. Then validate that the other one (Local) uses the JDBC URL.

        Assuming that you have the datasource defined in weblogic, here’s a quick test:
        1- Create a singleton class with a boolean variable “useJDBC”
        2- Create getters/setters for the variable in the singleton
        3- Use the singleton.instance().useJDBCUrl() in the following manner
        if(singleton.instance().useJDBCUrl())
        Configuration.createRootApplicationModule(AMName, “Local”);
        else
        Configuration.createRootApplicationModule(AMName, “Shared”);
        4-Wrap the Singleton class in a webservice
        – create a new webservices project
        – make it depend on the project which has the singleton
        – create a simple class which has a method
        update(boolean value){
        singleton.instance().setUseJDBCUrl(value); }
        – Right click on the class and generate a webservice
        5 – deploy your app with ways to test if you are using JDBC url or Datasource
        6 – Launch SOAP UI to connect to your webservice and play with the setUseJDBCUrl – true/false values and see what happens.

        Alternatively you can use a string in your singleton or a business rule to guide you to choose an instance. For example in cases where you want to be able to select the datasource or JDBC url based on environment

  2. Hello,

    Thanks for the blog… I have a query.. I am using a mapviewer url in my application to render maps. The mapvieewr in turn connects to the database to provide maps. When i deploy the application on remote server i get error dvt:26000 unable to find connection{}..

    PLease help…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s