cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Green" <>
Subject RE: cache and performance
Date Sun, 09 Jul 2000 16:09:51 GMT
Sorry for the delay - I haven't had time to read much email this week!

On Tue, 4 Jul 2000, Torsten Curdt wrote:

>BTW: Where should I place the connection definitions best? Is is
>      possible to established the connection when cocoon starts up
>      so I don't have to define and establish it in every XSP page?

Yes. There are two parts to this, if I understand your question correctly - 
avoiding repeating opening the connection for each page, and avoiding 
actually _specifying_ the connection name on each page. For the first, there 
are a number of free connection pooling classes out there - try a search on or . It's a very common 
requirement - in fact, there is connection pooling built in to the latest 
javax.sql package, IIRC.

The second can be done completely invisibly, thanks to XSP. If you have a 
Servlet 2.2 API-compatible servlet runner, insert a parameter like this into 
your web.xml:

        The database connection name passed to DBConnectionManager.

(The format of the web.xml file is part of the Servlet 2.2 API 
specification, so it should be the same for all compatible servlet runners).

Then create an XSP taglib for database access which gets this parameter from 
the servletContext variable (this variable is automatically declared by XSP 
as a variable local to the page generation method, so you don't have to do 
anything special to access it.) like this:

  servletContext.getInitParameter ("dbconnection")

(Of course, if you need to access more than one database in the same 
context, this simple approach won't work. In that case, perhaps have the 
most common connection name as a default, but make it overridable with an 
optional attribute to the database access tag(s).)

If you don't have a Servlet 2.2 API-compatible servlet runner, you can still 
do the same thing by implementing a singleton class to hold the "global" 
configuration details like the connection name.

There is a tradeoff in doing this. You gain the advantages of 
"normalization" (less redundancy, you can't forget to type in the connection 
name or misspell it - because you don't have to - etc.) but perhaps it's a 
little less clear what's going on. I think the former outweighs the latter.

Robin Green
i-tao Ltd.
4 Skyline Village
London E14 9TS
United Kingdom
Phone +44 20 7537 2233  Fax +44 70 8081 5118

Get Your Private, Free E-mail from MSN Hotmail at

View raw message