- Configuring a Datasource
- Adding Another Datasource
- Utilizing the New Datasource
- Wrapping Up
Utilizing the New Datasource
Now I want to move some of the services inside JBoss to my new datasource. The reason is simple: Hypersonic, while a good database, should not be used as the database of choice for a production and/or high-traffic system; MySQL and several other databases perform better in this role.
Java Messaging Service
One of the most common pieces of the JBoss server that uses the database is the messaging service. This is an area of the server that sees a lot of traffic and should be pointed to my new datasource. Two files in the deploy/jms directory define how the messaging service will utilize a datasource:
hsqldb-jdbc-state-service.xml
hsqldb-jdbc2-service.xml
First, I change the name of one of these files so that the appropriate type of database is clear: hsqldb-jdbc-state-service.xml is renamed to mysql-jdbc-state-service.xml.
The mysql-jdbc-state-service.xml file needs only one small change: The <depends> tag should reference the new ExampleDS datasource instead of DefaultDS. This will ensure that the datasource is started before the messaging service. I also change the comments to reflect that I'm using a MySQL database instead of the default Hypersonic.
Next, the hsqldb-jdbc2-service.xml file needs to be deleted and replaced. Because this file defines how the messaging service will use the database, we need database-specific information in the file. Fortunately, for the most common databases, the JBoss team has done the homework for me. I retrieve the MySQL-specific file (mysql-jdbc2-service.xml) from ${JBOSS.ROOT}/doc/examples/jms and place it in the deploy/jms directory. I make only one small edit in this file, changing the name of the datasource to ExampleDS to match the JNDI name I specified in the datasource configuration file.
Finally, to get the messaging service completely switched over, I change DefaultDS to ExampleDS in the conf/login-config.xml file. This setting tells JBoss to use the example datasource for login information pertaining to the messaging service.
Schedule Manager
If you're going to use the JBoss schedule manager and its database scheduler, you need to point it to the new datasource. The configuration file is located at deploy/schedule-manager-service.xml. Searching this file for DefaultDS turns up the mbean that needs to be reconfigured; I change the mbean DataSourceProperty to point to ExampleDS instead of DefaultDS.
NOTE
Be sure to review the SQL statement to make sure that it will work with your database.
Default Container-Managed Persistence
To change the default bean-persistence database, the conf/standardjbosscmp-jdbc.xml file needs to be updated, again changing DefaultDS to ExampleDS. Also, you have to update the <type-mapping> tag to match the new database; the correct value for this tag is further down in the file. For this example, I change the value to mySQL.
The conf/standardjaws.xml file should be updated in the same ways: changing DefaultDS to ExampleDS and updating the <type-mapping> tag to reflect the type of database being used.