tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Tomcat 4 JDBCRealm Connection Pooling
Date Wed, 13 Feb 2002 20:32:32 GMT

On Wed, 13 Feb 2002, Glenn Nielsen wrote:

> [snip]
> The addition of GlobalNamingResources and the UserDatabase slipped below
> my radar somehow.  I looked at the latest server.xml from CVS.  I grep'd
> the docs in CVS and didn't notice anything in the docs about these yet.
> The addition of GlobalNamingResources and the UserDatabase does add some
> interesting possiblities when configuring resources in Tomcat 4.
> > (Speaking of which, we might also consider writing a JDBCUserDatabase
> > implementation as well -- that way, the admin webapp can be used to update
> > the users in a database instead of in "conf/tomcat-users.xml" like
> > MemoryUserDatabase does.)
> >
> How would you like to proceed with this and the JDBCDataSourceRealm?

I think we need both JDBCDataSourceRealm (that supports the same database
configurability as JDBCRealm) and JDBCUserDatabase (which will have to
make more stringent restrictions on the table structures in use).

> > > In addition I use a different DataSource for normal customer dB
> > > application data and realm data.  The separation of these data sources
> > > makes sure that a customer application can't be spoofed somehow to
> > > compromise the entries in the db for a realm.
> > >
> >
> > This is all easy to set up.  It's also easy to set up a scenario where a
> > single connection pool, configured in the global resources, is actually
> > shared by the JDBCDataSourceRealm and made available to an application
> > (through a <ResourceLink>) if that is what your application requires.
> >
> Do you have an example of this?  I am very interested in being able to
> reduce the number of DBCP required, yet keep a complete separation of
> resources made available between virtual hosts.

Here's a scenario, and the way you might configure it:
- Define a connection pool in the Global JNDI resources
- Make it available to a theoretical "JDBCDataSourceRealm"
- Make it available to an application as a JNDI resource
  named "jdbc/MyDatabase".

In web.xml, the application would declare a <resource-ref> for the
resource named "jdbc/MyDatabase" in the usual way.

In server.xml, you would configure like this:

  <Server ...>

    <!-- Configure a JDBC connection pool in the global resources -->
      <Resource name="TheDatabase" auth="Container"
      <ResourceParams name="TheDatabase">
        ... configure the connection pool in the usual way ...

    <!-- Configure a Realm that uses this underlying connection pool -->
    <Realm className="org.apache.catalina.realm.JDBCDataSourceRealm"

    <!-- Configure a data source using the same underlying pool -->
    <Context path="/myapp" ...>
      <ResourceLink name="jdbc/MyDatabase" global="TheDatabase"/>


Doing things this way lets you substitute data source implementations
underneath either the server component (JDBCDataSourceRealm) or the
application, or change the decision about whether you are sharing the same
data source or not, without impacting any of the code that uses it.

As an additional advantage, the admin webapp will ultimately include a
nice UI to configure the global reosurces for you, plus a way to create
the resource links.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message