Advertise with us

Our eBooks

Migrate JBoss Datasources howto

This tutorial shows how you can automatically convert your Datasources from earlier JBoss AS versions (4-5-6) to JBoss AS 7 modular configuration using IronJacamar migration tool.

As most of you probably know, in previous versions of the application server, datasources and resource adapters were configured and deployed using a file with a suffix of *-ds.xml.

The IronJacamar 1.1.0 distribution contains a migration tool that can be used to convert these configuration files into the format expected by JBoss AS 7. The tool parses the source configuration file from the previous release, then creates and writes the XML configuration to an output file in the new format. The resulting XML can then be copied and pasted under the correct subsystem of JBoss AS 7 configuration file.

Download the IronJacamar 1.1 distribution from http://www.jboss.org/ironjacamar

Example: mysql-ds.xml (JBoss 4/5/6 Datasource for MySQL database)

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>x</user-name>
    <password>y</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>


Now move to the doc\as folder of your ironjacamar-1.1.0 distribution and issue the following command:

C:\ironjacamar-1.1.0.Alpha7\doc\as>converter.bat -ds mysql-ds.xml mysql-as7.xml

As you can see the converter batch file (converter.sh for Unix OS) accepts as parameter -ds to choose between resource adapter and datasource and then the INPUT xml file and the OUTPUT file.

Here's the generated mysql-as7.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<datasources>
  <datasource enabled="true" jndi-name="java:jboss/datasources/MySqlDS" jta="true" pool-name="MySqlDS" use-ccm="true" use-java-context="true">
    <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <datasource-class/>
    <driver/>
    <transaction-isolation>TRANSACTION_NONE</transaction-isolation>
    <pool>
      <prefill>false</prefill>
      <use-strict-min>false</use-strict-min>
      <flush-strategy>FailingConnectionOnly</flush-strategy>
    </pool>
    <security>
      <user-name>x</user-name>
      <password>y</password>
    </security>
    <validation>
      <validate-on-match>false</validate-on-match>
      <background-validation>false</background-validation>
      <use-fast-fail>false</use-fast-fail>
      <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter"/>
    </validation>
    <timeout>
      <xa-resource-timeout>0</xa-resource-timeout>
    </timeout>
    <statement>
      <track-statements>false</track-statements>
    </statement>
  </datasource>
</datasources>

As you can see the file has been enriched with some defaults for <pool> and <validation>, <timeout> and <statement> so that you further configure your Datasource in AS 7. One more important note is that this tool automatically converts the JNDI name binding to meet AS 7 standards (java:jboss/datasources/MySqlDS).

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.