Follow the instructions below to set up a remote H2 database.
Preparing the remote H2 DB
1. Download and install the H2 database on your computer. H2 installation guide can be found at: http://www.h2database.com/html/quickstart.html.
2. Go to the $H2_HOME/bin
directory and run the H2 network server starting script.
Tip
$H2_HOME
is the installation directory of H2.
3. Run the H2 database server with the following commands.
- For Linux:
$ ./h2.sh
- For Windows:
$ h2.bat
The script will start the database engine and bring up a pop-up window with a "Start Browser" button. The "Start Browser" button will open a web browser containing a client application, which you can connect to a database. H2 will automatically create a database if a database does not exist by the name you provide in the "JDBC URL" text box.
Setup Configuration Files
1. Edit the default database configuration defined in the master-datasources.xml
file located at $CARBON_HOME/repository/conf/datasources
directory instance as follows. Both the database configurations in registry.xml
and user-mgt.xml
refer this data source.
Note
The configurations should be replaced with your own database name, username, and password.
<datasource> <name>WSO2_CARBON_DB</name> <description>The datasource used for registry and user manager</description> <jndiConfig> <name>jdbc/WSO2CarbonDB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:h2:tcp://localhost/~/registryDB;create=true</url> <username>regadmin</username> <password>regadmin</password> <driverClassName>org.h2.Driver</driverClassName> <maxActive>80</maxActive> <maxWait>60000</maxWait> <minIdle>5</minIdle> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>
The database configuration options
- url - The URL of the database.
- username - The name of the database user.
- password - The password of the database user.
- driverClassName - The class name of the database driver.
- maxActive - The maximum number of active connections that can be allocated from this pool at the same time or negative for no limit.
- maxWait - The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.
- minIdle - The minimum number of active connections that can remain idle in the pool, without extra ones being created, or 0 to create none.
Setup Drivers
Tip
The H2 database version h2-1.2.140 and the related H2 database driver are currently shipped with the WSO2 BRS.
To use a new H2 database driver other than the version shipped with the WSO2 BRS, do the following.
1. Delete the following H2 database related JARs. Some of them may already be excluded from the configuration.
$CARBON_HOME/repository/components/plugins/h2-database-engine_1.2.140.wso2v3.jar
2. Copy the new H2 database driver (org.h2.Driver
) to $CARBON_HOME/repository/components/lib
. You can find the required driver JAR in $H2_HOME/bin/h2-*.jar
.
Create Database
Automatic Database Creation
1. The first time you start the server, run it with the -Dsetup
option. It will create the H2 database with all the underlying tables.
- For Linux:
sh wso2server.sh -Dsetup
- For Windows:
wso2server.bat -Dsetup
Manual Table Creation using scripts
1. Tables can be manually created by logging into the created database and running the following script in H2 shell or web console.
Note
Use the ./h2.sh
command to start the web console. After that copy the script text from the SQL file, paste it into the console and click "Run."
CARBON_HOME/dbscripts/h2.sql
2. After setting up the DB tables, start the server with the following commands.
- For Linux:
sh wso2server.sh
- For Windows:
wso2server.bat