Search This Blog

Wednesday 26 September 2007

Creating a data source from JDeveloper to a RAC 10.2.0.3 configuration

Creating a data source in JDeveloper that is using a RAC configuration URL can easily be achieved in JDeveloper by simply created a database connection and using a custom URL as shown below.

jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)

(HOST=aulnx11-vip.au.oracle.com)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)

(HOST=aulnx12-vip.au.oracle.com)(PORT=1521))
(CONNECT_DATA=(service_name=TGDG1_S1)))

This works I have done it many times but when you run your J2EE applications in the embedded server it will simply use the first host in the list, in this case aulnx11-vip.au.oracle.com. That may be all you need in which case setting up a database connection this way is fine, but typically when deployed to OAS you would set up your data source to use some connection pool properties in which case when testing your application you may invoke separate browser windows expecting to see connections to the various RAC nodes. This can also be done from JDeveloper when testing your application in the Emdedded OC4J Server using Tools -> Embdedded OC4J Server Preferences dialog. His how it's done

Note: Assuming a connection name in the IDE as "RAC10203".

1. Select Tools ->
Embdedded OC4J Server Preferences
2. Press the + symbol to expand the current workspace node
3. Press the + symbol to expand the Data Sources node

You will find 3 different type of entries for each connection in JDeveloper which basically allows for the 3 types supported in OC4J 10.1.3.x. That's a native data source, managed data source and a connection pool entry used by a managed data source. For more information about data sources refer to the following

Oracle® Containers for J2EE Services Guide
10g (10.1.3.1.0)

Part Number B28958-01
Data Sources

4. Click on the connection pool entry know as "jdev-connection-pool-RAC10203"
5. Set the initial limit to 4, max connections to 6 and
min limit to 4.
6. Click on the the managed data source "jdev-connection-managed-RAC10203" you will see that it's automatically setup to use the connection pool "jdev-connection-pool-RAC10203"

This is the default setup for each connection in jdeveloper and is the recommended way to use data sources in OC4J 10.1.3.x
.

7. Press OK to dismiss the dialog

Now when we run your J2EE application in the embedded OC4J server it will create 4 connections when the data source is started which will load balance between our RAC nodes in our case the 2 RAC nodes are
aulnx11 and aulnx12.

That will then ensure when you run your J2EE application in the embedded server that your database connection setup to access a RAC configuration can use either node depending on which connection is handed out to the page as the data source was setup with 4 connections and most likely 2 will belong to
aulnx11 and the other 2 to aulnx12.

This becomes more important at deployment time but gives you the chance to setup JDeveloper as if your running in an OAS environment with a data source using a balance of connections between your RAC instances.

His what the data source entry looks like which exists on the folder where your workspace files exist. The file with have a name $JDEV_WORK_DIR\{workpsace-folder}\{workspace-folder}-data-sources.xml:

<connection-pool
name="jdev-connection-pool-RAC10203"
initial-limit="4"
max-connections="6"
min-connections="4">
<connection-factory
factory-class="oracle.jdbc.pool.OracleDataSource"
user="scott"
password="->DataBase_User_i9JHwrMdRZMa2v5bKtQ3d8muOP6LzyvA"
url="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=aulnx11-vip.au.oracle.com)
(PORT=1521))(ADDRESS=(PROTOCOL=TCP)
(HOST=aulnx12-vip.au.oracle.com)
(PORT=1521))(CONNECT_DATA=(service_name=TGDG1_S1)))"/>
</connection-pool>
<managed-data-source
name="jdev-connection-managed-RAC10203"
jndi-name="jdbc/RAC10203DS"
connection-pool-name="jdev-connection-pool-RAC10203"/>

Now you can simply use this same data source entry on OAS when your ready
to deploy to OAS.

No comments: