commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Isaac Arias <>
Subject [DBCP] NamedDataSourceFactory to share DataSources between Servlet Contexts
Date Mon, 19 Aug 2002 22:14:39 GMT

Tomcat versions 4.1.x allow for the definition of
<GlobalNamingResources> that can be shared, through
JNDI, by all Servlet Contexts.

However, Tomcat 4.0.x does not support such a
construct. Using DBCP's BasicDataSourceFactory in
multiple contexts results in multiple DB connection
pools being created. Even if all contexts can share
the same pool, there is no direct way to specify this
in the server.xml file using DBCP.

I'm attaching a file called NamedDataSourceFactory
that adds a local static cache of DataSource objects
keyed by a user-specified name (pool name). The idea
is that if a context requests a DataSource with a
specific name, the factory first tries to find an
existing DataSource. If it finds one that was tagged
with that name, it returns it. If no DataSource exists
by that name, it creates a new one, returns it and
stores it in the Map to make it available for future

I realize that this file solves a very specific need
that we have and is probably not the best design. In
particular, caching DataSource objects at the Factory
level may be really bad :)

Additionally, if multiple <ReferenceParameters> blocks
are specified in the server.xml file with different DB
parameters (e.g. url, maxActive, etc.) but the same
pool name, only one pool will be created using the
attributes of the first reference called. So there is
an additional burden on the deployer to make sure that
JNDI DB references declared using this factory are
properly named.

In any event, it may be of use to someone or it might
spark a better idea on how to handle global pools for
different contexts in Tomcat 4.0.x or in other
applications of DBCP.

I appreciate any changes, comments or ideas about how
to do this properly.


Isaac Arias - CTO
Tokenzone, Inc.

Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
View raw message