Wednesday, February 27, 2013

Create a DB Adapter JNDI in WebLogic Server 11g

This blog post describes how to create a JNDI to a database in Oracle WebLogic 11g so that it can be referenced in your code.

For example, you may want to use the JNDI called eis/DB/DataWarehouse in your SOA code. This is done at design time in JDeveloper as shown in the following screenshot:



To create a JNDI to a database resource, two steps must be done on the WebLogic Server:
  • Create a data source and connection pool
  • Configure the Database Adapter


Create a Data Source

1. Log in to the WebLogic Server Administration Console

2. Click on Data Sources

3. Click on New > Generic Data Source

4. Enter a name for this data source (any name) and JNDI (this JNDI is typically used by Java code)


5. Click on Next

6. Choose your Database Drive (ask your DBA for assistance)

7. In the "Connection Properties" page, enter your database connection configuration

8. Keep navigating through the screens

9. In the "Select Targets", select which managed server you want this data source to be available to

10. Save and Active your changes


Configure the Database Adapter

1. On the WebLogic Administration Console, click on Deployments

2. Scroll down and click on DbAdapter > Configuration > Outbound Connection Pools

3. Click on New

4. Select the checkbox beside javax.resource.cci.ConnectionFactory and click Next

5. Provide a JNDI name (this JNDI is typically used by SOA/OSB code)


6. Click on Finish

7. Expand javax.resource.cci.ConnectionFactory

8. Locate and click on your JNDI that was just created (e.g., eis/DB/DataWarehouse)

9. On the "Outbound Connection Properties" page, enter the data source JNDI in the dataSourceName field, then click Save

* Note that if you configured your data source to use an XA driver, enter the JNDI name beside the xADataSourceName column instead.
10. You will now see this message:


11. On the navigation bar on the left, click on Deployments again

12. Scroll down and check the checkbox beside DbAdapter

13. Scroll back up and click on Update

14. Click Finish

15. Activate your changes


Summary

Here are a few takeaways to keep in mind:
  • The JNDI you define when creating the data source is typically used by Java applications
  • The JNDI you define when creating the DbAdapter is typically used by SOA/OSB applications
  • When creating a data source, choose "Generic Data Source" even if your database is an Oracle RAC or Microsoft SQL Server database (the "Multi Data Source" is used best for failover purposes)
  • When choosing the database driver for your data source, you must decide whether you want XA or non-XA drivers. This has design and coding implications
  • When configuring the DbAdapter, enter the JNDI of your data source in either the xADataSourceName or dataSourceName fields depending on how you created it
  • Don't forget to update the configuration plan when done!


Application versions:
  • Oracle WebLogic Server 11g (10.3+)

No comments: