Grid Services are deployed into the Globus web application, typically on a JBoss or Tomcat container. In this configuration there are 2 JNDI contexts, the Globus JNDI and the Container JNDI. Developers who are familiar with confguring JNDI datasources may be tempted to create the datasource in the container JNDI, but this will not work for Grid Services as they will not have visibility to this JNDI context.
This article is intended to provide the steps necessary to configure a C3P0 pooled datasource within the Globus JNDI context.
When configured as described here, your data sources JNDI name will follow this name structure.
|In this guide, $SERVICE_HOME will represent the location of your services top-level directory|
At the root level of each Introduce generated Grid Service is the file jndi-config.xml. This file contains configuration information for your service.
- Open your services $SERVICE_HOME/jndi-config.xml in an editor.
- Find the service element for your main service.
Your jndi-config.xml will have one service element for the main service and one for each service context. Make sure that you are adding the configuration to the main service entry.
- Within the service element add the following additional resource
- Update the JNDI resource to include specifics for your database
[DATASOURCE-NAME] Your datasource name. Example: "myserviceds" [DATABASE_DRIVER_CLASS] The driver specific to your database. Example: com.mysql.jdbc.Driver [JDCBURL] The JDBC URL appropriate for your database.
- The code above contains several pool settings that may not be appropriate for your application. Please refer to the C3P0 configuration documentation for details.
- Save the file.
|If your service is a caGrid Data Service that is backed by the Local caCORE SDK, the C3P0 jar may already be present in your services lib directory.|
- Download the C3P0 0.9.1.2 zip archive.
- Extract the zip file
- Copy the jar to your services lib directory
Here, we're assuming that you will be using the JNDI pool name directly in code to obtain a connection. You'll want to add the connector jar that is appropriate to your database type and version
- com.mysql.jdbc.Driver: mysql-connector-java-<version>-bin.jar
- MySQL Connector/J
This sample configuration uses the following:
- C3P0 datasource pool
- MySQL 5.0.45 database containing CSM tables.
The following jars were placed into the services lib directory
Now that we have our C3P0 pool configured we can add some code into our Service operations to obtain a connection and execute queries. Placing this code directly into your services client will not work.
- Add imports to your operation's class
- Add code to your operation