commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fumo, Vince" <Vince.F...@acs-inc.com>
Subject RE: DBCP and the ConnectionPoolDataSource Interface
Date Mon, 23 Feb 2004 17:22:56 GMT
Thanks Dirk, seems I was looking in DBCP 1.0, 1.1 added a bunch of stuff.
Thanks again

-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
Sent: Saturday, February 21, 2004 8:11 AM
To: Jakarta Commons Users List
Subject: Re: DBCP and the ConnectionPoolDataSource Interface


There are 2 almost separate connection pool implementations in the 
DBCP distribution.

The first one is located in org.apache.commons.dbcp.*
Starting from DriverConnectionFactory it builds a PoolingDataSource 
called BasicDataSource (the default tomcat datasource).
More info can be found here:
http://jakarta.apache.org/commons/dbcp/configuration.html
http://jakarta.apache.org/commons/dbcp/guide/index.html

It provides all pooling features for the DataSource.getConnection() 
method. (see configuration page for details)


The second pool implementation around the interface 
javax.sql.ConnectionPoolDataSource is located in:
org.apache.commons.dbcp.datasources.*
It is mostly used for its "per user" connection pools.

<Resource auth="Container" name="jdbc/peruser" 
type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource" />
<ResourceParams name="jdbc/peruser">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory</val
ue>
</parameter>
<parameter><name>defaultMaxActive</name><value>100</value></parameter>
<parameter><name>defaultMaxIdle</name><value>30</value></parameter>
<parameter><name>defaultMaxWait</name><value>10000</value></parameter>
<parameter><name>dataSourceName</name><value>java:comp/env/jdbc/peruserCPDS<
/value></parameter>
</ResourceParams>

The dataSourceName refers to a datasource implementing the 
javax.sql.ConnectionPoolDataSource interface.
You can use a database specific implementation or the generic DBCP one:
<Resource auth="Container" name="jdbc/peruserCPDS" 
type="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS" />
<ResourceParams name="jdbc/peruserCPDS">
<parameter>
   <name>factory</name>
   <value>org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS</value>
</parameter>
    <parameter><name>user</name><value></value></parameter>
    <parameter><name>password</name><value></value></parameter>
    <parameter><name>driver</name><value>...</value></parameter>
    <parameter><name>url</name><value>....</value></parameter>
</ResourceParams>

If you need a pooled getConnection() methods use BasicDataSource 
otherwise use PerUserPoolDataSource (with DriverAdapterCPDS or a 
database specific ConnectionPoolDataSource)

One last remark, if you going to use the MySQL driver for the 
ConnectionPoolDataSource be aware of the following issue:
http://issues.apache.org/eyebrowse/ReadMsg?listName=commons-user@jakarta.apa
che.org&msgNo=3792

Regards
Dirk

Fumo, Vince wrote:

> I have three different databases I need to manage and I want to use
> connection pooling datasources registered in JNDI as their commonality in
my
> application. From what I can gather, if the JDBC driver from the db vendor
> has a DataSource implementation that implements ConnectionPoolDataSource,
I
> can easily register it in JNDI. It's also my understanding that the
> management of the pool itself is not the responsibility of the individual
> JDBC driver. I'm hoping that DBCP can handle my management. 
> 
> What I'd like to implement is a simple method  that will take a
> ConnectionPoolDataSource object, wrap it in pool management and return a
> PoolingDataSource object that I can then register in JNDI. 
> 
> I've looked at the Dialog in the javadoc and I understand how to create a
> pool given a connection string (using the DriverConnectionFactory) but I'm
> not sure how to replace this ConnectionFactory with the
> ConnectionPoolDataSource object. I'm not even sure if this is what I
should
> be doing.
> 
> I'm sorry if this seems a simple question, but I've looked everywhere and
I
> can't seem to find anything that references a connection between
> ConnectionPoolDataSource and DBCP (other than the reference in the javadoc
> for DriverAdapterCPDS.
> 
> Thanks for your help.




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message