08 August 2009

Creating connection factory for database adapters


While configuring a database adapter, we need to specify the JNDI name for the connection factory. At run time, this name is used by the application server to get the Datasource JNDI and connection parameters for the database.

When any adapter is configured in JDeveloper using the adapter configuration wizard, this name is automatically configured as eis/DB/ <Connection Name>.
In SOA suite 10.1.x , after the adapter was configured, the wsdl file used to have the database connection parameters in the form of .mcf properties. Due to this reason, even though the connection factory was not created on the server, the code used to work fine. In fact even though the connection factory was created and was pointing to some other database, the mcf parameters used to overwrite those values.

In 11g, things are bit different. Now, the JNDI name for the connection factory and name of the connection is no more part of the adapter wsdl file. These values are stored as a part of a .jca file.
Name of the file is < Adapter Name > _db.jca. Also, this file does not contain all those mcf properties which were present earlier. So if the connection factory is not created , or not pointing to expected Datasource JNDI location, then the process throws error saying that the JCA binding was unable to create the connection.

However, there is a small step different here. Even if the correct connection factory JNDI name is mentioned in this jca file and it is present on server, the process still throws the same error.

The reason is that the JNDI name has not been added to the resource adapter that has been deployed on the server. This issue can be solved by adding this connection factory instance to the weblogic-ra.xml file of the datbase adapter application which is deployed on the server

This can be achieved in following steps:

1) Create the corresponding Data source using the console.

2) Go to following location:
<Oracle_SOA1>\(folder where SOA server installed) \soa\connectors
This folder contains the application rar files for all the adpaters that are deployed.
Each of this will contain a weblogic-ra.xml file which stores the resource adapter details.
What we need to do is add our connection factory in this file.

3) Take backup of the folder(so that if you mess up then you have the copy present). Then in some other location on your machine, copy the DbAdapter.rar file and unzip it. It will have a meta-inf folder inside which we have our dear weblogic-ra.xml file present.

4) Open this file. You can see that this file has information about the connection factory for SOA Demo application. This basically means that, it has already given you a sample connection factory which connects to the DEV_SOAINFRA schema of your SOA database.(DEV is the prefix, it is what you chose to give while installing.) However, for all other databases, we would have to add entries in this file. To do this, in the connection-definition-group node, at the end, create one more
connection-instance node. In the following example, I have added a connection-instance node with Connection factory as "eis/DB/XEKetan" and Datasource JNDI as "jdbc/XEKetanDS"







5) Once this is done, save the file and again create the rar file.

6) Replace the adapter's rar file with this new rar file.

7) In the console homepage, go to Deployments (click the link present in the left pane) . This will show list of the deployed applications. It has one application as database adapter (DbAdapter).
Select the check box for the application and click update button.

8) Select "Redeploy this application using the following deployment files:" radio button

9) For the source path, if the path is different, then browse and give this rar files location. Click Next.

10) It will ask for reviewing the choices. If values are correct, click Finish. Adapter will be updated and then it will again come back to deployments page. Server restart is not required.


Once this is done, we can use this connection factory in our SOA project.


1 comment:

Shirish Kumar said...

Thanks Ketan, it's a good post.