From f8d90fcc0ac64e4a3f8b4711a3883add019c59a7 Mon Sep 17 00:00:00 2001 From: Jan Wieck Date: Thu, 9 Oct 2003 01:17:07 +0000 Subject: [PATCH] Protected access to variable m_preparedCount via synchronized function to prevent multiple threads using automatic cursors on the same connection from stomping over each others cursor. Jan --- .../postgresql/jdbc1/AbstractJdbc1Statement.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java index 88f7891d07..0a11f3a3b0 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java @@ -26,7 +26,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Vector; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.39 2003/09/23 06:13:52 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.40 2003/10/09 01:17:07 wieck Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement @@ -73,7 +73,15 @@ public abstract class AbstractJdbc1Statement implements BaseStatement protected boolean m_statementIsCursor = false; private boolean m_useServerPrepare = false; + + // m_preparedCount is used for naming of auto-cursors and must + // be synchronized so that multiple threads using the same + // connection don't stomp over each others cursors. private static int m_preparedCount = 1; + private synchronized static int next_preparedCount() + { + return m_preparedCount++; + } //Used by the callablestatement style methods private static final String JDBC_SYNTAX = "{[? =] call ([? [,?]*]) }"; @@ -316,7 +324,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement { if (m_statementName == null) { - m_statementName = "JDBC_STATEMENT_" + m_preparedCount++; + m_statementName = "JDBC_STATEMENT_" + next_preparedCount(); m_origSqlFragments = new String[m_sqlFragments.length]; m_executeSqlFragments = new String[m_sqlFragments.length]; System.arraycopy(m_sqlFragments, 0, m_origSqlFragments, 0, m_sqlFragments.length); @@ -375,7 +383,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement // The first thing to do is transform the statement text into the cursor form. String[] cursorBasedSql = new String[m_sqlFragments.length]; // Pinch the prepared count for our own nefarious purposes. - String statementName = "JDBC_CURS_" + m_preparedCount++; + String statementName = "JDBC_CURS_" + next_preparedCount(); // Setup the cursor decleration. // Note that we don't need a BEGIN because we've already // made sure we're executing inside a transaction.