Under the covers, the console creates a Geronimo deployment plan for the database pool, and then deploys the appropriate RAR file with that plan using the same deployment logic that the command-line deployer uses. After deploying a database pool, if you look at the list of deployed RAR files, you'll see an entry for the database pool.
![]() | Note |
|---|---|
The name (or |
In other words, the console is not doing anything special, and a database pool can be configured and deployed manually. This may be especially useful if you want to deploy the same pool to multiple servers, or save the configuration for every developer to apply to their local instance later (though you can also use Geronimo Plugins to copy the pool directly from server to server). This section describes how to configure and deploy database pools using the underlying text files and command-line tools.
No matter how you plan to deploy the database pool, the basic configuration format is the same. The only difference is that for server-wide and application-scoped database pools, the configuration goes in a standalone file, while for client-scoped database pools, the same configuration information is embedded in the module's Geronimo configuration file.
![]() | Note |
|---|---|
Geronimo does not yet handle drivers that supply their own
|
Since the pool is deployed as a connector, the configuration file is a connector deployment plan, using the same format covered in Chapter 13, J2EE Connectors (RARs) [DRAFT (1.0)]. For now, we'll look at the key elements of this file as far as database pools are concerned. Example 6.1, “Database Pool Deployment Plan” shows a sample database pool deployment plan. Note that the configuration information shown there may be saved to a file on its own or embedded in another file depending on how you deploy the database pool -- see Section 6.4.2, “Deploying a Database Pool” for more details.
Example 6.1. Database Pool Deployment Plan
<connector
xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1">
<environment
xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<moduleId>
<groupId>test</groupId>
<artifactId>TestDatabase</artifactId>
<version>1.0</version>
<type>rar</type>
</moduleId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>3.1.12</version>
<type>jar</type>
</dependency>
</dependencies>
</environment>
<resourceadapter>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>
javax.sql.DataSource
</connectionfactory-interface>
<connectiondefinition-instance>
<name>MySQLDataSource</name>
<config-property-setting name="UserName">
dbuser
</config-property-setting>
<config-property-setting name="Password">
dbpw
</config-property-setting>
<config-property-setting name="Driver">
org.postgresql.Driver
</config-property-setting>
<config-property-setting name="ConnectionURL">
jdbc:postgresql://localhost/mydb
</config-property-setting>
<config-property-setting name="CommitBeforeAutocommit">
true
</config-property-setting>
<config-property-setting name="ExceptionSorterClass">
org.tranql.connector.NoExceptionsAreFatalSorter
</config-property-setting>
<connectionmanager>
<local-transaction/>
<single-pool>
<max-size>10</max-size>
<min-size>0</min-size>
<blocking-timeout-milliseconds>
5000
</blocking-timeout-milliseconds>
<idle-timeout-minutes>30</idle-timeout-minutes>
<match-one/>
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
</connector>The key attribute and elements here are:
The unique name identifying this module, broken up by the child elements into its constituent parts. (For more information on module IDs see Section 4.1.1, “Module IDs”.) If this is deployed as a server-wide connection pool, the module ID specified here can be passed to the deploy tool to start or stop the pool.
Each dependency identifies either a Geronimo module that this connection pool depends on, or a JAR that must be loaded for the connection pool to use -- this is generally used for the JDBC driver JAR. This element may be repeated if multiple JARs need to be loaded. The child elements hold the different components of the module ID for the dependency.
Must be javax.sql.DataSource
The name that other modules will use to refer to this connection pool. This must be unique within any given scope (server, application, etc.), and it will be easiest to configure references if this is further unique across all resources deployed at any scope in the server.
Specifies a value for one of the configuration properties for the connector. The name attribute identifies the property, and the content of this element is the value to set for that property. The available properties are listed in Table 6.1, “Connection Pool Configuration Properties”.
The maximum number of simultaneous connections to allow for this connection pool.
The minimum size of the connection pool. If the pool falls below this size, it will be refilled to the minimum size. However, the pool is not initialized to this size until the first time a connection attempt is made. The default value is 0.
If a caller requests a connection and all the connections in the pool are in use, the caller will wait this long for a connection to become available. If the timeout expires without an available connection, an exception will be thrown.
This interval defines how often the pool is checked for unused connections. If during that check any individual connection has been unused for at least this long, it will be closed and removed from the pool. The default value of 0 disables idle timeouts.
For a more extensive discussion of the
connectionmanager settings, see Section 13.3.2.2.1, “Connection Manager Configuration”.
The configuration properties for the connection pool are listed in Table 6.1, “Connection Pool Configuration Properties”. Note that the properties should always be specified exactly as listed (many databases use different names for the username and password, but Geronimo will handle that).
Table 6.1. Connection Pool Configuration Properties
| Name | Description |
|---|---|
| Driver | The class name of the JDBC driver |
| ConnectionURL | The JDBC URL used to connect to the database |
| UserName | The user name used to connect to the database |
| Password | The password used to connect to the database |
| CommitBeforeAutocommit | If the JDBC driver does not commit pending work when
setAutoCommit(true) is called, then this
should be set to true to work around that.
It's always safest to set it to true, but the
performance is better for JDBC-compliant drivers when this is
set to false (which is the default). |
| ExceptionSorterClass | The JDBC pool needs to know whether a given SQLException
means that the connection has failed, or if it's just a normal
SQL problem. This class is responsible for determining whether
any given SQLException is fatal (and if so, the connection will
be closed and released from the pool). In general, this is a
product-specific decision, but product-specific implementations
are not available as of Milestone 4. The current options are
NoExceptionsAreFatalSorter or
AllExceptionsAreFatalSorter (both in the
package org.tranql.connector). This is mainly
important if some SQLExceptions indicate or result in a broken
database connection, and Geronimo should open new connections to
compensate. |
![]() | Note |
|---|---|
It is not currently possible to pass arbitrary properties to the JDBC driver while making the connection. However, you may use a complex ConnectionURL if the driver allows additional properties to be added to the end of the URL instead. |
Once the database pool deployment plan has been prepared, you can deploy the pool using one of the three methods described here. In any of these cases, you'll need the deployment plan, and the TranQL RAR file.
To deploy a server-wide database pool, you'll create a deployment plan using the format described in Section 6.4.1, “Configuring a Database Pool” and then deploy the connection pool using that plan.
First you should save the database pool deployment plan to a
file like database-pool.xml (the name can be
anything you like). Then you need to locate the TranQL RAR and deploy
the pool using a command like this:
java -jar bin/deployer.jar deploy database-pool.xml \ repository/tranql/tranql-connector/1.2/tranql-connector-1.2.rar
Note that this example assumes that the server is running, and
it can be run from any directory, so long as you point it to the
deployer JAR in geronimo/bin.
The two arguments should point to the TranQL RAR file and the database
pool deployment plan (the order doesn't matter). If the server is not
running, you can use the command distribute instead
of deploy though then you'll still have to start
the configuration once the server is running. For more information on
deployment commands, see Section 10.4, “The Deploy Tool”.
Other application modules can map resources to that database pool using the procedure described in Section 6.5, “Using a Database Pool”.
In contrast to server-wide database pools, application-scoped database pools are only visible to a single application by default, which must be packaged as an EAR.
To deploy an application-scoped database pool, you'll include
the TranQL Connector RAR as a module in your application EAR (for
normal JDBC pools; XA database pools would use a product-specific
TranQL RAR, which should be in the same location.). First you should
save the database pool deployment plan to a file like
database-pool.xml (the name can be anything you
like). Then you need to locate the TranQL RAR, and add both of these
to your EAR.
For example, the EAR structure might look like this:
jar -tf my-app.ear my-web-app.war my-ejbs.jar tranql-connector-1.2.rar database-pool.xml META-INF/application.xml META-INF/geronimo-application.xml
Notice the TranQL RAR and the database configuration file. You
should add a reference to the TranQL RAR to the standard
META-INF/application.xml deployment descriptor,
and add a reference to the database pool deployment plan to the
META-INF/geronimo-application.xml deployment
plan. This might be the only entry in the
geronimo-application.xml file, so you'll need to
create that file if you don't have one already.
The application.xml file for the EAR above
would look like this:
META-INF/application.xml
<application
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<module>
<ejb>my-ejbs.jar</ejb>
</module>
<module>
<web>
<web-uri>my-web-app.war</web-uri>
<context-root>/my-web-app</context-root>
</web>
</module>
<module>
<connector>tranql-connector-1.2.rar</connector>
</module>
</application>Notice the final module entry for the RAR.
The geronimo-application.xml file
identifying the database pool deployment plan would look like
this:
META-INF/geronimo-application.xml
<application
xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.1">
<environment>
<moduleId>
<artifactId>MyApplication</artifactId>
</moduleId>
</environment>
<module>
<connector>tranql-connector-1.2.rar</connector>
<alt-dd>database-plan.xml</alt-dd>
</module>
</application>Using the alt-dd element, the deployment plan
for the application indicates that the database pool deployment plan
for the connector is included as a separate file in the EAR, instead
of being packaged into the RAR. The elements here look very similar to
the elements in the standard application.xml
deployment descriptor, but if we specify an alt-dd
there it means an alternate standard J2EE deployment descriptor,
whereas specifying the alt-dd here means an
alternate Geronimo deployment plan for the connector.
For more information on the
geronimo-application.xml file, see Chapter 15, Enterprise Applications (EARs) [DRAFT (1.0)].
The most restricted type of database pools, client-scoped database pools are only visible to the application client module that declares them. These pools are not visible to either other modules in the same application or to other applications in the same server.
To deploy a client-scoped database pool, you'll refer to a
common copy of the TranQL Connector RAR (for normal JDBC pools) --
make sure it appears at geronimo/repository/tranql/tranql-connector/1.2/tranql-connector-1.2.rar.
(XA database pools would use a product-specific TranQL RAR, which
should be in a similar location.)
A client-scoped connection pool is declared in the Geronimo
deployment plan for the application client module that should have
access to the pool. The plan will have an additional
resource element containing the pool definition. A
deployment plan that declared a pool using the same configuration
shown in Example 6.1, “Database Pool Deployment Plan” would look like
this:
META-INF/geronimo-application-client.xml
<application-client xmlns=
"http://geronimo.apache.org/xml/ns/j2ee/application-client-1.1">
<server-environment
xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<moduleId>
<artifactId>MyClientJSR77</artifactId>
</moduleId>
</server-environment>
<client-environment
xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<moduleId>
<artifactId>MyClient</artifactId>
</moduleId>
</client-environment>
...
<resource>
<external-rar>
tranql/tranql-connector/1.2/rar
</external-rar>
<connector
xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.1">
<environment
xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<moduleId>
<groupId>test</groupId>
<artifactId>TestDatabase</artifactId>
<version>1.0</version>
<type>rar</type>
</moduleId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>3.1.12</version>
<type>jar</type>
</dependency>
</dependencies>
</environment>
<resourceadapter>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>
javax.sql.DataSource
</connectionfactory-interface>
<connectiondefinition-instance>
<name>MySQLDataSource</name>
<config-property-setting name="UserName">
dbuser
</config-property-setting>
<config-property-setting name="Password">
dbpw
</config-property-setting>
<config-property-setting name="Driver">
org.postgresql.Driver
</config-property-setting>
<config-property-setting name="ConnectionURL">
jdbc:postgresql://localhost/mydb
</config-property-setting>
<config-property-setting
name="CommitBeforeAutocommit">
true
</config-property-setting>
<config-property-setting
name="ExceptionSorterClass">
org.tranql.connector.NoExceptionsAreFatalSorter
</config-property-setting>
<connectionmanager>
<local-transaction/>
<single-pool>
<max-size>10</max-size>
<min-size>0</min-size>
<blocking-timeout-milliseconds>
5000
</blocking-timeout-milliseconds>
<idle-timeout-minutes>30</idle-timeout-minutes>
<match-one/>
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
</connector>
</resource>
</application-client>The important elements here are:
This element contains the entire definition of the client-scoped database pool
This is the Module ID of the RAR in the Geronimo repository.
This element contains all the data from the connector configuration file. The content is no different that the content of the deployment plan would have been for the server-wide or application-scoped database pools.
In the next section you'll see how to access that pool from application code.