Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 50798 invoked from network); 2 Jan 2011 19:12:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Jan 2011 19:12:39 -0000 Received: (qmail 78388 invoked by uid 500); 2 Jan 2011 19:12:38 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 78268 invoked by uid 500); 2 Jan 2011 19:12:37 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 31370 invoked by uid 99); 2 Jan 2011 14:05:44 -0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1293977112; bh=uJkDpoKLpa4gnHya9oMP+D4iHiEXMZsbiE6ExcgykRg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=5vbstCLGDU+Dur/WNiorazLZMktR9y0zKQFYEG4/s1g6wZqRYTLah26ywwewU5fDVDxgjMX0QOX6ir+y2WJ16Ttd/JPmWyI5/AX5L1O4zUSBvAiBU+TLqqFTXa0hwDymW55JSr+yZL05vAdC3jY1r/Vc2phn2GMtW0JfKeGSFTU= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=mERe0PEKOCO8OYeEUkI2a9Ltl8LH2JYQF6s1kJHOfSolp/bnCmE9Fh9gNRtuxNSf9SsLbtCYn8r1lRqAWV0sA8LCieBqp1ecRPXYIVFPcLDjGov5jNVffJ2FWOabx9L7rz9Ay5bGEgwk/meGzqdRCNlik+eLtqvKCJhGbsY8wGo=; Message-ID: <104305.65042.qm@web33205.mail.mud.yahoo.com> X-YMail-OSG: 7kzwFaoVM1muZp3BDIl4JIV_DueovK1fHmEtrtPH4mTBOfu VKtlFWOc1.FSPMuNOOFedjEaEt5OXaSsUQzOQ_X4SWEzkbzS4UtSMb4dEl7s 0gaakr1_3wIvot0xVg7lr83_aGtJKI.yX6Y4rH3nPsvdhWUCNfipEas6J6gX Pz2RsthZflSBQooNyeZhi.HsJvcmDmHbWaY4yGwkIGMgeVGnpxaq6MiwyiAj Q8A__EFpIcHgCeGnh3amrjxzx62f_PpxUaHbK1OpfxgmSUV8JNdXXhL7T_lI VSgqCOOdNvGseEn1gAdww7NnR50Rt0tNFHpMDV_15kcpdgdpOETU8dBUWEv5 seRd.5KG7E_.GRQWGqqLLw32Tx2IjWsEW8x7VsEVbPookE5lwRiaQvWRj41D UQz0RIZeUWUae X-Mailer: YahooMailRC/553 YahooMailWebService/0.8.107.285259 Date: Sun, 2 Jan 2011 06:05:12 -0800 (PST) From: Nishant Ranjan Subject: [dbcp] is statement pool working? To: user@commons.apache.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-258906467-1293977112=:65042" X-Virus-Checked: Checked by ClamAV on apache.org --0-258906467-1293977112=:65042 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi,=0A=0ATo enable statement pooling using DBCP, one needs to provide a =0A= KeyedObjectPoolFactory while creating a PoolableConnectionFactory. This its= elf =0Ais a bit complicated and confusing. (see: =0Ahttp://mail-archives.ap= ache.org/mod_mbox/commons-user/200503.mbox/%3C003301c52797$9794bf20$0302a8c= 0@vikram%3E).=0A A reference implementation on how to activate connection p= ooling has been =0Aprovided. =0A=0A=0A=0A// create your connection pool=0AG= enericObjectPool pool =3D new GenericObjectPool();=0A=0A// and set its prop= erties=0A// ..=0A=0A// then your connection factory=0AConnectionFactory cf = =3D new DriverManagerConnectionFactory(.....);=0A=0A// then a factory for y= our prepared statements=0AKeyedObjectPoolFactory kpf =3D new GenericKeyedOb= jectPoolFactory(null, 8);=0A=0A// finally, your overall connection factory= =0APoolableConnectionFactory pcf =3D new PoolableConnectionFactory(cf, pool= , kpf, =0Anull, false, true);=0ASo far so good.=0A=0AHowever, the problem s= tarts to happen when one wants to use a statement out of =0Athis statement = pool. (You would want to use one if you have created one!) The =0Aonly way = of doing this seems to be by creating a PoolingConnection. This is =0Awhere= the problem actually starts.=0A=0AThere is no way of getting a PoolingConn= ection from the classes which were used =0Ato create the statement pool inc= luding the PoolableConnectionFactory (where an =0Ainstance of PoolingConnec= tion is actually created everytime a new connection is =0Acreated if a stat= ement pool factory was provided earlier - the source code =0Areveals that).= However one can get a Connection from the DataSource that was =0Acreated b= y this PooableConnectionFactory and use this Connection to create a =0APool= ingConnection.=0A=0A// suppose we already have a DataSource called dataSour= ce=0A=0AConnection conn =3D dataSource.getConnection();=0APoolingConnection= poolConn =3D new PoolingConnection (conn);=0A=0A When a connection is cre= ated in this way and then poolConn.prepareStatement(); =0Ais called, it giv= es the following error:=0A=0Ajava.sql.SQLException: Statement pool is null = - closed or invalid =0APoolingConnection.=0A at =0Aorg.apache.commons.db= cp.PoolingConnection.prepareStatement(PoolingConnection.java:103)=0A=0A=0AH= owever when I implement a semaphore to keep track of the statement pool (an= =0Ainstance of KeyedObjectPool) during creating of a Connection and then p= rovide =0Athis statement while creating PoolingConnection, there are no err= ors and =0Aeverything works fine. This also makes sense when I look at the = source code. =0A=0A=0AThis makes me think that there has to be some way of = retrieving the statement =0Apool that is created by the PoolableConnectionF= actory whenever a new Connection =0Ais created. Am I coming to the right co= nclusions? =0A=0A=0AIf so, then I wonder if in the current implementation o= f DBCP, is statement =0Apooling at all working? Should someone raise an iss= ue in JIRA? Can I suggest a =0Asolution?=0A=0AAs this is the 3rd day that I= am using DBCP, I might be missing something =0Acompletely. I would be happ= y to be relieved of a blind spot.=0A=0A Thanks & Regards,=0ANishant Ranjan= =0A=0A --0-258906467-1293977112=:65042--