JBoss migration – the data source

I have spent a lot of time lately trying to create a migration plan for an application currently running on JBoss 4.2.2. Since this application development started a few migration attempts to newer versions of JBoss have been done (see for 5.1) but as it seems each version has different style configuration files and this application is expected to have a long lifetime the work seems a bit futile so in parallel of
migrating to JBoss-7.1.1 I’ve tried to migrate to Tomcat since our use of EJB’s is limited and other MBeans can be refactored in simpler ways. Unlike JBoss, Tomcat configuration seems to be eternal and by all means simpler.

1. The data source

The purpose of the following configurations is to define an JNDI DataSource which can be then used in the application allowing DB configuration to be separated from the application itself.

1.1 JBoss 4.2.2

In JBoss 4.2.2 the datasource was defined in a ${name}-ds.xml in the following format:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>XOracleDS</jndi-name>
        <connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
        <!-- ... -->
        <metadata>
            <type-mapping>Oracle9i</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>

The JNDI name will be: java:/XOracleDS.

1.2 JBoss 7.1.1

In JBoss 7.1.1 first a module has to be defined as jboss-7/modules/com/oracle/ojdbc4/main containg the ojdbc14.jar and a module.xml.

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle.ojdbc4">
    <resources>
        <resource-root path="ojdbc14.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>

Then the file jboss-7/standalone/configuration/standalone.xml has to be modified. The datasources part should be changed to:

...
<datasources>
<datasource jndi-name="java:/XOracleDS" pool-name="XOracle" enabled="true" use-java-context="true">
    <connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
    <driver>oracle</driver>
    <pool>
        <min-pool-size>3</min-pool-size>
        <max-pool-size>20</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>...</user-name>
        <password>...</password>
    </security>
</datasource>
<drivers>
    <driver name="oracle" module="com.oracle.ojdbc4">
        <driver-class>oracle.jdbc.OracleDriver</driver-class>
    </driver>
</drivers>
</datasources>
...

Note that this method deploys the JDBC driver as a core module. There is an alternative to install as a deployment which can be found here. This link is one of the basis, even if not always complete for migration information.
The JNDI name will be: java:/XOracleDS.

1.3 Tomcat

In Tomcat the definition of the datasource is (can be) done in a context.xml file located in $CATALINA_HOME/conf/context.xml

<Context>
...
<Resource name="jdbc/XOracleDS"
            auth="Container"
            type="javax.sql.DataSource"
            username="..."
            password="..."
            driverClassName="oracle.jdbc.driver.OracleDriver"
            url="jdbc:oracle:thin:@localhost:1521:XE"
            maxActive="8"
            maxIdle="4"/>
</Context>

One thing to note is that the Tomcat JNDI name will be: java:/comp/env/jdbc/XOracleDS since the prefix is mandatory.

 

Leave a Reply

*