Removing Hypersonic


Hypersonic is a great database for testing an application, but it isn't production ready. In Chapter 4, you saw how to switch to another database. If you aren't using Hypersonic, you can remove the entire service. Hypersonic doesn't listen for connections from the outside world unless you ask it to, so you don't need to worry about securing it. However, you might not want an extra relational database hanging around in memory. It's fairly lightweight, but you'll probably be better off just getting rid of it.

How do I do that?

The hsqldb-ds.xml file not only configures the Hypersonic datasources, but also it has the MBeans that control the entire embedded database service. Removing this file will remove all traces of Hypersonic.

It sounds trivial, and it would be except that several other services depend on Hypersonic. We'll go through the changes now, assuming you have created a MySQL database as shown in Chapter 4, and that the ToDo application is already switched over to using that.

The first service is the EJB timer service, in ejb-deployer.xml. You should replace the reference to DefaultDS with a reference to the correct datasource. In Chapter 4, we chose the name MySqlDS. The change is simple:

     <!-- A persistence policy that persists timers to a database -->     <mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy"             name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">         <!-- DataSource JNDI name -->         <depends optional-attribute-name="DataSource">             jboss.jca:service=DataSourceBinding,name=MySqlDS         </depends>         <!-- The plugin that handles database persistence -->         <attribute name="DatabasePersistencePlugin">             org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin         </attribute>     </mbean> 

JMS also requires persistence changes to be made. If you aren't using JMS and you chose to remove it from your configuration, you can stop here. Otherwise, go to the deploy/jms directory and look for hsqldb-jdbc2-service.xml and hsqldb-jdbc-state-service.xml.

hsqldb-jdbc2-service.xml controls message persistence. You can remove it completely and replace it with a database-specific file from docs/examples/jms. For MySQL, copy mysql-jdbc2-service.xml into the jms directory.

hsqldb-jdbc-state-service.xml isn't quite so simple. There are no database-specific templates for this. You'll need to update the datasource dependency manually:

     <mbean code="org.jboss.mq.sm.jdbc.JDBCStateManager"            name="jboss.mq:service=StateManager">         <depends optional-attribute-name="ConnectionManager">             jboss.jca:service=DataSourceBinding,name=MySqlDS         </depends>         <!-- ... -->     </mbean> 

This datasource reference needs to be the same as the datasource you saw earlier, in the jbossmq security domain in login-config.xml. You'll want to update that now too:

     <application-policy name="jbossmq">         <authentication>             <login-module                 code="org.jboss.security.auth.spi.DatabaseServerLoginModule"                flag="required">                 <module-option name="unauthenticatedIdentity">guest                 </module-option>                 <module-option name="dsJndiName">java:/MySqlDS</module-option>                 <module-option name="principalsQuery">                     SELECT PASSWD FROM JMS_USERS WHERE USERID=?                 </module-option>                 <module-option name="rolesQuery">                     SELECT ROLEID, 'Roles' FROM JMS_ROLES WHERE USERID=?                 </module-option>             </login-module>         </authentication>     </application-policy> 

The final dependency on DefaultDS is uuid-key-generator.sar. If you aren't using the JBoss UUID key generator, remove this service from the deploy directory. If you are, you'll need to update the META-INF/jboss-service.xml file to reference the preferred datasource:

     <mbean code="org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory"              name="jboss:service=KeyGeneratorFactory,type=HiLo">         <!-- ... -->         <depends optional-attribute-name="DataSource">             jboss.jca:service=DataSourceBinding,name=MySqlDS         </depends>         <!-- ... -->     </mbean> 

Unfortunately, this service is not provided in exploded form, so you'll have you unpack the archive to get to it.

What just happened?

You removed Hypersonic and updated, or removed, the services that depend on it. All of the persistent services will write their tables into the new database. If you've kept them around and restarted JBoss, you should find several new database tables in your external database:

     mysql> show tables in jbossdb;     +-------------------+     | Tables_in_jbossdb |     +-------------------+     | Comment           |     | HILOSEQUENCES     |     | JMS_ROLES         |     | JMS_SUBSCRIPTIONS |     | JMS_TRANSACTIONS  |     | JMS_USERS         |     | TIMERS            |     | Task              |     | jms_messages      |     +-------------------+     9 rows in set (0.14 sec) 

You could have saved yourself some trouble by creating a replacement DefaultDS. Then it wouldn't have been necessary to change all the datasource references. However, it's important to be explicit about your configuration in a production machine. The extra effort is worth the peace of mind of knowing that all your persistent services are configured correctly.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net