Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 77821 invoked from network); 22 Sep 2007 13:06:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Sep 2007 13:06:38 -0000 Received: (qmail 55527 invoked by uid 500); 22 Sep 2007 13:06:28 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 55494 invoked by uid 500); 22 Sep 2007 13:06:28 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 55483 invoked by uid 99); 22 Sep 2007 13:06:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Sep 2007 06:06:28 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.43.22] (HELO sca-ea-mail-4.sun.com) (192.18.43.22) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Sep 2007 13:06:25 +0000 Received: from dm-uk-02.uk.sun.com ([129.156.101.196]) by sca-ea-mail-4.sun.com (8.13.6+Sun/8.12.9) with ESMTP id l8MD64G4017946 for ; Sat, 22 Sep 2007 13:06:04 GMT Received: from barman.uk.sun.com (barman.UK.Sun.COM [129.156.132.12]) by dm-uk-02.uk.sun.com (8.13.7+Sun/8.13.6/ENSMAIL,v2.2) with ESMTP id l8MD64m8026273 for ; Sat, 22 Sep 2007 14:06:04 +0100 (BST) Received: from vpn-129-150-121-224.uk.sun.com ([129.150.121.224]) by barman.uk.sun.com with esmtp (Exim 4.42) id 1IZ4ih-0002I6-VQ for derby-user@db.apache.org; Sat, 22 Sep 2007 14:08:28 +0100 Message-ID: <46F5133B.1050606@sun.com> Date: Sat, 22 Sep 2007 14:06:03 +0100 From: Alan Burlison User-Agent: Thunderbird 2.0.0.4 (X11/20070814) MIME-Version: 1.0 To: Derby Discussion Subject: Re: What exactly are the *ConnectionPoolDataSource classes for? References: <46F05666.2020405@sun.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Knut Anders Hatlen wrote: > Derby doesn't provide connection pooling, but ConnectionPoolDataSource > can be used as a basic building block for a connection pool. A > ConnectionPoolDataSource creates PooledConnections, whereas a DataSource > creates Connections. A PooledConnection is just a wrapper around a > physical connection so that you can open/close logical Connection > objects without actually closing the underlying connection. Although > ConnectionPoolDataSource makes it easier to implement a connection pool, > it is possible to build a connection pool around DataSource too. I don't > know how the connection pool in Tomcat works, but if the example code > normally uses DataSource, I assume that it has implemented the wrapping > of the physical connections itself and you'll be fine with DataSource. > > HTH, It did, thanks. In the end I didn't use the connection pool built into Tomcat. As far as I can tell it requires that you set up a JNDI data source to reference the pool. The problem with that is you have to put a copy of the underlying JDBC driver into the global Tomcat /lib directory, as the pool is set up before Tomcat starts up any webapps. This makes it impossible to provide an entirely stand-alone WAR file that uses the Tomcat connection pool. Instead I used MiniConnectionPoolManager (http://www.source-code.biz/snippets/java/8.htm) and passed it an instance of the Derby ConnectionPoolDataSource class. I then layered a custom implementation of DataSource on top of the pool manager, so I could then set the custom DataSource as the default JSP data source, and also push a reference to it into the webapp application scope. Here's what I ended up with: Custom DataSource->MiniConnectionPoolManager->ConnectionPoolDataSource The only wrinkle was that MiniConnectionPoolManager doesn't cache connections by user ID, so I had to make the getConnection(String username, String password) method in the custom DataSource throw an exception if it was called. This was no big deal as my application only uses a single username to access the database. -- Alan Burlison --