pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: List <pgsql-jdbc@postgresql.org>
Subject: statement caching proof of concept
Date: Mon, 19 Jun 2006 12:55:46 -0400
Message-ID: <4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com> (raw)

This is just proof of concept. More work has to be done to make it  
build properly and work properly under different jdk's

Couple of questions.

1) What to do if there are multiple concurrent requests per  
connection for the same statement?
	1) we could just allow it
	2) we could return a non-cacheable preparedstatement
	3) throw an exception

2) Is it enough to cache prepared statements or should we cache  
statements too?

Note: this work is based completely on apache's dbcp statement  
caching implementation and this will be noted in the final code.

Attachments:

statementcache.diff (application/octet-stream, 8.4K) download Index: build.xml =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/build.xml,v retrieving revision 1.69 diff -c -b -r1.69 build.xml *** build.xml 8 Jun 2006 10:34:50 -0000 1.69 --- build.xml 19 Jun 2006 16:41:18 -0000 *************** *** 155,160 **** --- 155,163 ---- <include name="${package}/jdbc3/Jdbc3ResultSet.java" if="jdbc3"/> <include name="${package}/jdbc3/Jdbc3ResultSetMetaData.java.java" if="jdbc3"/> <include name="${package}/jdbc3/Jdbc3Statement.java" if="jdbc3"/> + <include name="${package}/jdbc3/CacheablePreparedStatement.java" if="jdbc3"/> + <include name="${package}/jdbc3/CacheConnection.java" if="jdbc3"/> + <include name="${package}/jdbc3/StatementPool.java" if="jdbc3"/> <!-- jdbc3g subpackage --> <include name="${package}/jdbc3g/*.java" if="jdbc3g" /> *************** *** 222,231 **** <condition property="connectclass" value="org.postgresql.jdbc2.Jdbc2Connection"> <equals arg1="${jdbc2}" arg2="true"/> </condition> ! <condition property="connectclass" value="org.postgresql.jdbc3.Jdbc3Connection"> <equals arg1="${jdbc3}" arg2="true"/> </condition> ! <condition property="connectclass" value="org.postgresql.jdbc3g.Jdbc3gConnection"> <equals arg1="${jdbc3g}" arg2="true"/> </condition> <condition property="connectclass" value="org.postgresql.jdbc4.Jdbc4Connection"> --- 225,234 ---- <condition property="connectclass" value="org.postgresql.jdbc2.Jdbc2Connection"> <equals arg1="${jdbc2}" arg2="true"/> </condition> ! <condition property="connectclass" value="org.postgresql.jdbc3.CacheConnection"> <equals arg1="${jdbc3}" arg2="true"/> </condition> ! <condition property="connectclass" value="org.postgresql.jdbc3g.CacheConnection"> <equals arg1="${jdbc3g}" arg2="true"/> </condition> <condition property="connectclass" value="org.postgresql.jdbc4.Jdbc4Connection"> *************** *** 323,330 **** <!-- Password must be something. Doesn't matter if trust is used! --> <property name="password" value="password" /> <property name="preparethreshold" value="0" /> ! <property name="loglevel" value="0" /> ! <property name="protocolVersion" value="0" /> <!-- The tests now build to a separate directory and jarfile from the driver build, to ensure we're really testing against the jar we just --- 326,333 ---- <!-- Password must be something. Doesn't matter if trust is used! --> <property name="password" value="password" /> <property name="preparethreshold" value="0" /> ! <property name="loglevel" value="1" /> ! <property name="protocolVersion" value="3" /> <!-- The tests now build to a separate directory and jarfile from the driver build, to ensure we're really testing against the jar we just Index: org/postgresql/jdbc2/AbstractJdbc2Connection.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v retrieving revision 1.37 diff -c -b -r1.37 AbstractJdbc2Connection.java *** org/postgresql/jdbc2/AbstractJdbc2Connection.java 24 Nov 2005 06:44:21 -0000 1.37 --- org/postgresql/jdbc2/AbstractJdbc2Connection.java 19 Jun 2006 16:41:19 -0000 *************** *** 15,21 **** import java.util.*; import org.postgresql.core.*; import org.postgresql.Driver; - import org.postgresql.PGConnection; import org.postgresql.PGNotification; import org.postgresql.fastpath.Fastpath; import org.postgresql.largeobject.LargeObjectManager; --- 15,20 ---- *************** *** 1077,1080 **** --- 1076,1080 ---- { return bindStringAsVarchar; } + } Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v retrieving revision 1.91 diff -c -b -r1.91 AbstractJdbc2Statement.java *** org/postgresql/jdbc2/AbstractJdbc2Statement.java 8 Jun 2006 10:34:50 -0000 1.91 --- org/postgresql/jdbc2/AbstractJdbc2Statement.java 19 Jun 2006 16:41:21 -0000 *************** *** 419,431 **** // Every statement execution clears any previous warnings. clearWarnings(); ! // Close any existing resultsets associated with this statement. ! while (firstUnclosedResult != null) ! { ! if (firstUnclosedResult.getResultSet() != null) ! firstUnclosedResult.getResultSet().close(); ! firstUnclosedResult = firstUnclosedResult.getNext(); ! } if (lastSimpleQuery != null) { lastSimpleQuery.close(); --- 419,425 ---- // Every statement execution clears any previous warnings. clearWarnings(); ! this.closeResultSets(); if (lastSimpleQuery != null) { lastSimpleQuery.close(); *************** *** 711,724 **** // closing an already closed Statement is a no-op. if (isClosed) return ; - // Force the ResultSet(s) to close - while (firstUnclosedResult != null) - { - if (firstUnclosedResult.getResultSet() != null) - firstUnclosedResult.getResultSet().close(); - firstUnclosedResult = firstUnclosedResult.getNext(); - } if (lastSimpleQuery != null) lastSimpleQuery.close(); --- 705,712 ---- // closing an already closed Statement is a no-op. if (isClosed) return ; + closeResultSets(); if (lastSimpleQuery != null) lastSimpleQuery.close(); *************** *** 727,736 **** preparedQuery.close(); // Disasociate it from us - result = firstUnclosedResult = null; isClosed = true; } /** * This finalizer ensures that statements that have allocated server-side * resources free them when they become unreferenced. --- 715,735 ---- preparedQuery.close(); // Disasociate it from us isClosed = true; } + public void closeResultSets() throws SQLException + { + // Force the ResultSet(s) to close + while (firstUnclosedResult != null) + { + if (firstUnclosedResult.getResultSet() != null) + firstUnclosedResult.getResultSet().close(); + firstUnclosedResult = firstUnclosedResult.getNext(); + } + result = firstUnclosedResult = null; + + } /** * This finalizer ensures that statements that have allocated server-side * resources free them when they become unreferenced. Index: org/postgresql/test/jdbc2/ConnectionTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/ConnectionTest.java,v retrieving revision 1.21 diff -c -b -r1.21 ConnectionTest.java *** org/postgresql/test/jdbc2/ConnectionTest.java 24 Nov 2005 02:31:43 -0000 1.21 --- org/postgresql/test/jdbc2/ConnectionTest.java 19 Jun 2006 16:41:21 -0000 *************** *** 9,14 **** --- 9,15 ---- */ package org.postgresql.test.jdbc2; + import org.postgresql.Driver; import org.postgresql.test.TestUtil; import junit.framework.TestCase; import java.sql.*; *************** *** 22,27 **** --- 23,32 ---- public class ConnectionTest extends TestCase { + static + { + Driver.setLogLevel(0); + } /* * Constructor */ Index: org/postgresql/test/jdbc2/PreparedStatementTest.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/PreparedStatementTest.java,v retrieving revision 1.16 diff -c -b -r1.16 PreparedStatementTest.java *** org/postgresql/test/jdbc2/PreparedStatementTest.java 15 May 2006 09:35:57 -0000 1.16 --- org/postgresql/test/jdbc2/PreparedStatementTest.java 19 Jun 2006 16:41:21 -0000 *************** *** 25,37 **** public PreparedStatementTest(String name) { super(name); - - try - { - org.postgresql.Driver driver = new org.postgresql.Driver(); - } - catch (Exception ex) - {;} } protected void setUp() throws Exception --- 25,30 ----
StatementPool.java (application/octet-stream, 2.2K) download CacheConnection.java (application/octet-stream, 4.0K) download CacheablePreparedStatement.java (application/octet-stream, 1.2K) download

view thread (18+ messages)  latest in thread

Message-ID: <4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com>
Permalink:  ../4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com/
Also on:    postgresql.org/message-id/4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com
  Subject: Re: statement caching proof of concept
  In-Reply-To: <4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com>
  References: <4077BF73-482B-46C8-B65D-2E1FD2465294@fastcrypt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox