Using a database in a Wonderland module at the server-side.#

Tested with Wonderland source code v0.5 on Windows 7.

a) Standard configuration:#

When you download the Wonderland source code, compile everything and start the server, a derby database will be loaded automatically in the background. This derby database will run as embedded database, meaning that no other JVM will have access to it. If you check the file “wonderland/web/server/domain.xml” you will see the configuration information for the database connection, which should look something like this:
<resources>
....
<jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" name="wonderlandpool">
      <property name="databaseName" value="${wonderland.run.dir}/wonderlanddb"/>
      <property name="connectionAttributes" value=";create=true"/>
    </jdbc-connection-pool>
    <jdbc-resource jndi-name="jdbc/wonderlanddb" pool-name="wonderlandpool"/>

<jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" name="userpool">
      <property name="databaseName" value="${wonderland.run.dir}/userdb"/>
      <property name="connectionAttributes" value=";create=true"/>
</jdbc-connection-pool>
<jdbc-resource jndi-name="jdbc/userpool" pool-name="userpool"/>
</resources>

In general you will have to use a service(-module) on the Darkstar/Wonderland server to perform your SQL queries if you want to utilize a database in the server part of your module. For more technical details concerning this requirement you may check out this discussion, especially Jonathan Kaplan’s postings: working with a database. For the rest of this walkthrough we assume that you use the “sql-service-module” which can be found in the “unstable” modules folder of the supplementary wonderland modules repository.

Now with your “sql-service-module” configured properly (check out that module’s enclosed README file for instructions) you will want to query a database. Basically you have two possibilities to configure your database environment:

  • either you leave the Wonderland database untouched and set up a separate SQL server which will be used solely by the “sql-service-module
  • or you change the configuration for Wonderland server to use the same (for multiple JVM’s usable) database instance as the “sql-service-module
The first method is pretty straight forward (download e.g. a MySQL server, install it locally, set parameters as described in the “sql-service-module” README).

Regarding the second choice you will find a brief summary below how to configure your system once with an independent MySQL database and once with the provided derby server switched into a network mode.

b) using an additional MySQL server for Wonderland AND modules:#

After you set up a MySQL server on your machine you will have to make the following changes to Wonderland to make it use that MySQL server as well:

1) change the settings for the database connections in the file “wonderland/web/server/domain.xml” to something like this (replace username, password, port, etc. as needed):
<resources>
....
<jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" res-type="javax.sql.ConnectionPoolDataSource" name="userpool" ping="true">
	<property name="databaseName" value="userdb" />
	<property name="portNumber" value="8081" />
	<property name="serverName" value="localhost" />
	<property name="user" value="root" />
	<property name="password" value="root" />
	<property name="connectionAttributes" value=";create=true"/>
</jdbc-connection-pool>
<jdbc-resource pool-name="userpool" description="User pool" jndi-name="jdbc/userpool" />

<jdbc-connection-pool datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" res-type="javax.sql.ConnectionPoolDataSource" name="wonderlandpool" ping="true">
	<property name="databaseName" value="wonderlanddb" />
	<property name="portNumber" value="8081" />
	<property name="serverName" value="localhost" />
	<property name="user" value="root" />
	<property name="password" value="root" />
	<property name="connectionAttributes" value=";create=true"/>
</jdbc-connection-pool>
<jdbc-resource pool-name="wonderlandpool" description="Wonderland database pool" jndi-name="jdbc/wonderlanddb"/>
</resources>
2) copy the “mysql-connector-java-X.Y.Z-bin.jar” file to the folder “wonderland/web/server/lib/
3) add the mysql connector library to the classpath in the file “wonderland/web/server/build.xml
(e.g. at line ~100 <checksumfileset file="${web.dir}/server/lib/mysql-connector-java-5.1.12-bin.jar" prefix="webserver"/>)
4) add the “userpool” and “wonderlanddb” databases to your MySQL server
That should do the trick and your Wonderland server should use the same database which can be used by the “sql-service-module”.

c) using the former embedded derby database in networked mode for Wonderland AND modules:#

1) again change the settings for the database connections in the file “wonderland/web/server/domain.xml” to something like this (replace username, password, port, etc. as needed):
<resources>
....
<jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" name="wonderlandpool">
	<property name="databaseName" value="wonderlanddb"/>
	<property name="connectionAttributes" value=";create=true"/>
	<property name="User" value="APP"/>
	<property name="Password" value="APP"/>
</jdbc-connection-pool>
<jdbc-resource jndi-name="jdbc/wonderlanddb" pool-name="wonderlandpool"/>

<jdbc-connection-pool datasource-classname="org.apache.derby.jdbc.ClientDataSource" name="userpool">
	<property name="databaseName" value="userdb"/>
	<property name="connectionAttributes" value=";create=true"/>
	<property name="User" value="APP"/>
	<property name="Password" value="APP"/>
</jdbc-connection-pool>
<jdbc-resource jndi-name="jdbc/userpool" pool-name="userpool"/>
</resources>

2) add the following parameter to the file “wonderland/web/server/web-default.properties”:
derby.drda.startNetworkServer=true

If you restart the Wonderland server the derby database instance should start in networked mode now which can be accessed by e.g. the “sql-service-module”.

TODO
  • check what happens to the ”userpool” database with the derby database being in networked mode
  • check if it’s needed to set user/password parameter with the database being in networked mode

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-2) was last changed on 23-Jul-2010 09:55 by Christian Schratter