Bug 968361 - Improve database plugin design to support connection pooling

Thomas Segismont tsegismo at redhat.com
Thu Jan 2 13:32:16 UTC 2014


Hi everyone,

I just pushed commit 2b810f1c9fa247a9d8ddf08d2b9ba93c9e1cf2a6 to master.

This changeset introduces a new API for database plugins and deprecates 
the previous one. Compatibility with the previous API will be maintained 
until next major version of RHQ.

The 'rhq-database-plugin' was based on 
org.rhq.plugins.database.DatabaseComponent interface which encouraged 
plugin authors to share a single JDBC connection across database 
components. This was wrong for various reasons (connection leaks, 
concurrent JDBC calls... etc).

The new API introduces three important classes:
* org.rhq.plugins.database.PooledConnectionProvider
* org.rhq.plugins.database.BasePooledConnectionProvider
* org.rhq.plugins.database.ConnectionPoolingSupport

BasePooledConnectionProvider is a base implementation of a 
PooledConnectionProvider. Plugin authors should create a concrete 
implementation of BasePooledConnectionProvider which overrides the 
#getDriverClass() method. This is important if a database plugin embeds 
a JDBC driver: the database-specific driver class must be loaded by the 
child plugin classloader.

ConnectionPoolingSupport helps to manage the compatibility with the old 
API. It's a contract that all new database resource components should 
obey to. It declares the following methods:
* #supportsConnectionPooling()
* #getPooledConnectionProvider()
Results of calls to #supportsConnectionPooling() 
#getPooledConnectionProvider() must be consistent. In practice, a top 
level server database component should be able to create a 
PooledConnectionProvider instance, and child servers and services should 
indicate they support connection pooling only if their parent component 
does.

The 'rhq-database-plugin' embeds the BoneCP library (JDBC connection 
pooling) and its dependencies (Google's Guava). Child plugins will have 
all the classes accessible as soon as they have this node in their 
plugin descriptor:
===
<depends plugin="Database" useClasses="true"/>
===

This changeset includes the necessary changes to support connection 
pooling in the Oracle, Postgres and MySQL plugins.

Thanks to Elias Ross for contributing the original patch from which this 
changeset is derived.

Regards,
Thomas

Happy new year!


More information about the rhq-devel mailing list