Search code examples
derbywildfly

How to shutdown embedded Derby which is defined as a DataSource properly on WildFly


When I defined a Derby DataSource on WildFly normally, db.lck file is left undeleted and it indicates the database was not shutdown properly at every shutdown of WildFly. because embedded Derby requires a special shutdown procedure that is acquiring a new connection with JDBC URL which ended with ";shutdown=true" string.

So, I need something like a shutdown-hook which executes the shutdown procedure. I found that old JBoss have a way to achieve it:

https://developer.jboss.org/wiki/SetUpADerbyDatasource http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.jboss.jbossas/jboss-as-varia/6.0.0.Final/org/jboss/jdbc/DerbyDatabase.java

But I don't know how to apply that on recent WildFly because it looks like "mbean" and "depends" element not allowed anymore on its data source definition, and I can't find its equivalent on recent WildFly.

I think "connection-listener-class" variable of datasource definition is considerable, and it might be a way to achieve it. I haven't tried it yet but it looks like bit complex and I'm not sure it works as expected.

So, is there a way to define a shutdown-hook which executes shutdown procedure of Derby with recent WildFly?

EDIT:

I posted an instruction of installing Apache Derby to WildFly which includes my solution. http://www.nailedtothex.org/roller/kyle/entry/installing-apache-derby-to-wildfly


Solution

  • I found a better solution with MBean. it simply executes the shutdown procedure at every WildFly shutdown.

    Just clone this repository and build a jar, put it to $WILDFLY_HOME/standalone/deployments. there are various files in the project so it's annoying to paste all of files here.

    A dependency to org.jboss.ironjacamar.jdbcadapters, connection-listener-class and connection-listener-property are unnecessary so now $WILDFLY_HOME/modules/org/apache/derby/main/module.xml can be simplified like the following:

    module.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="org.apache.derby">
        <resources>
            <resource-root path="derby.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>