|
|
The solution is to switch to a different RDBMS such as MySQL, PostgreSQL or Oracle, which supports multiple connections. In this tutorial, we will look at how to configure WSO2 WSAS to work with MySQL & PostgreSQL RDBMSs.
MySQL and WSAS have to be configured as follows:
mysql> create database wso2wsas_db;
<?xml version='1.0' encoding='utf-8'?>Note that you have to specify the correct values for the connection.url, connection.username and connection.password properties. Also, the value of the hbm2ddl.auto property is "true", which will create all the tables when WSAS is started up for the first time.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/wso2wsas_db</property>
<property name="connection.username">wso2wsas</property>
<property name="connection.password">wso2wsas</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<!--property name="show_sql">true</property-->
<!-- Posible values for hbm2ddl.auto (update | create | create-drop)-->
<property name="hbm2ddl.auto">create</property>
<mapping resource="wso2wsas.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<Context path="/wso2wsas" >Change this to:
<Resource name="jdbc/wso2wsas_db"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="wso2wsas"
password="wso2wsas"
driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
url="jdbc:derby:../database/WSO2WSAS_DB;create=true"/>
</Context>
<Context path="/wso2wsas" >
<Resource name="jdbc/wso2wsas_db"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="wso2wsas"
password="wso2wsas"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/wso2wsas_db"/>
</Context>
<Context path="/wso2wsas" docBase="wso2wsas" reloadable="true"Change this to:
crossContext="true">
<Resource name="jdbc/wso2wsas_db" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/wso2wsas_db">
<parameter><name>username</name><value>
wso2wsas</value></parameter>
<parameter><name>password</name><value>
wso2wsas</value></parameter>
<parameter><name>driverClassName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value></parameter>
<parameter><name>url</name>
<value>jdbc:derby:../database/WSO2WSAS_DB;create=true</value>
</parameter>
</ResourceParams>
</Context>
<Context path="/wso2wsas" docBase="wso2wsas"
reloadable="true" crossContext="true">
<Resource name="jdbc/wso2wsas_db" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/wso2wsas_db">
<parameter><name>username</name><value>
wso2wsas</value></parameter>
<parameter><name>password</name><value>
wso2wsas</value></parameter>
<parameter><name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value></parameter>
<parameter><name>url</name>
<value>jdbc:mysql://127.0.0.1:3306/wso2wsas_db</value>
</parameter>
</ResourceParams>
</Context>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/wso2wsas_db</jndi-name>
<connection-url>
jdbc:mysql://127.0.0.1:3306/wso2wsas_db</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>wso2wsas</user-name>
<password>wso2wsas</password>
</local-tx-datasource>
</datasources>
<hibernate-configuration>
<session-factory>
<!--Settings to connect to the database via a JNDI datasource-->
<property name="connection.datasource">
java:comp/env/jdbc/wso2wsas_db</property>
<property name="connection.pool_size">1</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="wso2wsas.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<property name="hbm2ddl.auto">create</property>If this line is left uncommented, the startup time of WSAS would be unnecessarily high since Hibernate has to scan the entire database to check whether any database tables have to be created or updated.
The steps are same as the above MySQL scenario. The only differences are the following parameters: Database driver : org.postgresql.Driver Database URL : jdbc:postgres:wso2wsas_db Hibernate SQL Dialect : org.hibernate.dialect.PostgreSQLDialect You would also have to use the proper jar containing the PostgreSQL JDBC driver. You can download the driver from jdbc.postgresql.org/download Create WSAS database as follows:
$ createdb wso2wsas_db -E unicode
You could add a new wso2wsas user with username 'wso2wsas' and password 'wso2wsas' as follows:
postgres@azeez:~$ psql wso2wsas_db
Welcome to psql 8.0.3, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
wso2wsas_db=# create user wso2wsas with password 'wso2wsas';
Similarly, for any other RDBMS, you could simply create the WSAS database, and configure the database connection parameters as explained above, and start WSAS, at which point the database tables should get created and populated.
WSO2 WSAS 2.0 & 2.1
Rest of the WSO2 WSAS HOWTO Series
Afkham Azeez, Architect & Product Manager of WSO2 WSO2 WSAS, WSO2 Inc. Azeez @ WSO2
What if I want to create a
The default configuration
I mean Derby Embedded Server
Yes it is possible to do
Why not using a Derby