![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]()
|
Pooling Agents Standard Database Connections PoolMan Configuration Pooling with PostgreSQL 7.3 PostgreSQL 7.3, JNDI and Tomcat Pooling AgentsThere is no mechanism within Castor JDO to provide pooling of JDBC drivers. Rather, Castor JDO relies on the drivers or external driver wrappers to implement a pooling mechanism. Some drivers, such as Oracle, provides a pooling mechanism in the driver. For those that do not, there are tools such as PoolMan, Proxool and Jakarta's DBCP project. Although PoolMan is no longer being maintained, it is still one of the best open-source JDBC poolers that can turn almost any JDBC driver into a pooled data source. The last released version that is recommended is version 2.0.4, as the 2.1 version was still in development when the project stopped. Here, I'll go over the various usage of the PostgreSQL driver with Castor. We start with the most basic configurations that do not use any pooling, to those with pooling via PoolMan. Finally, I'll include how to configure the upcoming pooling version of the PostgreSQL JDBC driver ths will be usable with PostgreSQL 7.3, and how to setup a Tomcat JNDI context that Castor can use to get a pooled JDBC connection. Standard Database ConnectionsA standard database.xml entry for using PostgreSQL without pooling looks like this: On the other hand, if you wanted to use the PostgresqlDataSource, you would use the data-source tag instead, and the connection entry would look like this: (Note that only versions before 7.3 of the PostgreSQL JDBC driver include this class) PoolMan ConfigurationNow, the standard PostgresqlDataSource is not a pooling data source, so it doesn't provide us much use here. Instead, we'll install poolman, and create a poolman.xml entry for our database connection to get the pooling behavior. In the poolman.xml, our connection information would look like this: In this sample, poolman will have a datasource called appPool, that will have a min of 2 connections for the database, and will max out at 10 connections. Now, can use poolman with Castor in two ways. The first is as a driver, and the second is as a data source. Here are the two possible entries for the database.xml file... first, the driver version: and now the data-source version: As you can see, we have placed all of the connection information in the poolman.xml configuration file, so Castor just needs to connect to poolman. Either configuration will work, as Castor does not care from where it gets the connection from. Pooling with PostgreSQL 7.3In the 7.3 release of PostgreSQL, they will start providing a pooling mechanism with their driver. The Castor CVS repository includes a beta version of the driver with this functionality. Here is the 'current' configuration needed for the upcoming 7.3 release of PostgreSQL. (Unless they change it.) Note that in this pooling mechanism currently lacks some features of PoolMan, such as timing out idle connections and removing failed connections from the pool. In this case, we can create the following data-source entry in the database.xml file to provide for our connections with Castor. PostgreSQL 7.3, JNDI and TomcatFinally, I want to show the configuration for using a pooling data-source for Castor which is retrieved from a JNDI context that Apache fills. The first example is using the PostgreSQL pooling data-source, and the second is using Castor. The information to gain here is that we did not need to change the database.xml file or the webapp's web.xml file to achieve this. First, we modify the deployment context for the webapp in Tomcat-4.0.4 for our webapp in the conf/server.xml directory. We add the following information: Here, we are using the PostgreSQL PGObjectFactory which provides the JNDI server (Tomcat) the ability to create the correct data source. Now, the web.xml file for the webapp needs to be updated too. Note that we are only calling the ref type a DataSource object, not using the PostgreSQL class name. This will enable us to make changes easily. Now,in the dataabase.xml file that Castor uses, we no longer list the driver or data-source tag, but use the JNDI one, and it is simply this: | ||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |