Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f8d90fc

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
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
1 parent 67afe3d commit f8d90fc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.sql.Types;
2727
import java.util.Vector;
2828

29-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.39 2003/09/23 06:13:52 barry Exp $
29+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.40 2003/10/09 01:17:07 wieck Exp $
3030
* This class defines methods of the jdbc1 specification. This class is
3131
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
3232
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -73,7 +73,15 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
7373
protected boolean m_statementIsCursor = false;
7474

7575
private boolean m_useServerPrepare = false;
76+
77+
// m_preparedCount is used for naming of auto-cursors and must
78+
// be synchronized so that multiple threads using the same
79+
// connection don't stomp over each others cursors.
7680
private static int m_preparedCount = 1;
81+
private synchronized static int next_preparedCount()
82+
{
83+
return m_preparedCount++;
84+
}
7785

7886
//Used by the callablestatement style methods
7987
private static final String JDBC_SYNTAX = "{[? =] call <some_function> ([? [,?]*]) }";
@@ -316,7 +324,7 @@ public boolean execute() throws SQLException
316324
{
317325
if (m_statementName == null)
318326
{
319-
m_statementName = "JDBC_STATEMENT_" + m_preparedCount++;
327+
m_statementName = "JDBC_STATEMENT_" + next_preparedCount();
320328
m_origSqlFragments = new String[m_sqlFragments.length];
321329
m_executeSqlFragments = new String[m_sqlFragments.length];
322330
System.arraycopy(m_sqlFragments, 0, m_origSqlFragments, 0, m_sqlFragments.length);
@@ -375,7 +383,7 @@ else if (fetchSize > 0 && !connection.getAutoCommit())
375383
// The first thing to do is transform the statement text into the cursor form.
376384
String[] cursorBasedSql = new String[m_sqlFragments.length];
377385
// Pinch the prepared count for our own nefarious purposes.
378-
String statementName = "JDBC_CURS_" + m_preparedCount++;
386+
String statementName = "JDBC_CURS_" + next_preparedCount();
379387
// Setup the cursor decleration.
380388
// Note that we don't need a BEGIN because we've already
381389
// made sure we're executing inside a transaction.

0 commit comments

Comments
 (0)