This document explains how to setup a database and some data sources as required by the samples. Most samples require an Apache Derby installation whereas a few would require a MySQL setup.
Apache Synapse has the ability to lookup and update relational databases through JDBC. Any database engine that provides JDBC drivers can be integrated with Synapse using the dblookup and dbreport mediators. Synapse ships with a collection of samples which demonstrates various aspects of dblookup, dbreport mediators and database integration. This article describes how to setup the databases, sample tables and reusable data sources required to try these examples out.
Most samples assume Apache Derby is used as the database engine. And therefore this article also focuses mainly on setting up Apache Derby. Byt in reality any database engine can be used to run these samples. The database schema and SQL queries described here will work with any database engine. However in such cases some minor changes should be made to the Synapse configuration files.
Some samples involve invoking database stored procedures from Synapse. For these samples MySQL database engine is assumed. Therefore this article provides some basic information on setting up MySQL for the example scenarios.
To start with, download the latest binary distribution of Apache Derby. Extract the downloaded archive to a suitable location in the local disk and switch to the 'bin' directory of the installation. Start the Derby network server by executing the 'startNetworkServer' startup script. An output similar to the following will be displayed as the database engine starts up.
Now launch the Derby client tool by executing the 'ij' script. This will give a command prompt where you can execute various command and SQL queries. Execute the following connect statement to create a fresh database named 'synapsedb' and obtain a connection to it.
Now execute the following SQL query to create a new table.
Insert some sample data to the table by executing following statements.
Now we have finished setting up the Derby server for the samples. As the final step we should copy the Derby JDBC drivers to Synapse 'lib' directory. Locate the following jar files in Derby installation and copy them into Synapse.
This section assumes that you already have a MySQL server instance up and running. For details on installing MySQL, please refer the relevant MySQL documentation.
Create a new database named 'synapsedb' in MySQL. Then execute the SQL queries given in the previous section to create a table named 'company' and insert some sample data into it. Then execute the following two commands in MySQL client to create two stored procedures.
Then you should download the MySQL JDBC driver and deploy it into the 'lib' directory of Synapse.
You can run the given samples using any RDBMS engine you prefer. In that case please make sure you do the following.
Synapse is capable of connecting to databases through predefined data sources. This enables database connection pooling and connection reuse. Different instances of the database mediators (dblookup/dbreport) can either use different data sources or share the same data source.
Data sources are configured in the synapse.properties file which can be found in the 'lib' directory of the Synapse installation. Currently Synapse supports following types of data sources.
Both these types of data sources are based on Apache DBCP.
Following section describes how to setup two data sources as required by some of the database integration samples of Synapse. First, it is required to setup two Derby databases. So launch 'ij' client tool for Derby and create two databases named 'lookupdb' and 'reportdb'. Specify the username and password to be 'synapse' for both databases. Create the 'company' table in each database and add some sample data as described under Setting Up Apache Derby section.
Now you can define two data sources for these databases by adding the following entries to the synapse.properties file.
Here we are defining two data sources named 'lookupds' and 'reportds'. The first data source is defined as a BasicDataSource and the other one is defined as a PerUserPoolDataSource. Note the various parameters we have specified for each data source thereby further customizing the behavior of each data source.