List:Commits« Previous MessageNext Message »
From:mmatthews Date:April 4 2006 3:53pm
Subject:Connector/J commit: r5133 - branches/branch_5_0/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
   branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
Log:
Relaxing synchronization to prevent deadlocks.

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-04-04 00:03:07 UTC (rev 5132)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java	2006-04-04 15:53:24 UTC (rev 5133)
@@ -1410,6 +1410,13 @@
 	Connection(String hostToConnectTo, int portToConnectTo, Properties info,
 			String databaseToConnectTo, String url)
 			throws SQLException {
+		this.charsetToNumBytesMap = new HashMap();
+		
+		if (getCacheCallableStatements()) {
+			this.parsedCallableStatementCache = new LRUCache(
+					getCallableStatementCacheSize());
+		}
+		
 		this.connectionCreationTimeMillis = System.currentTimeMillis();
 		this.pointOfOrigin = new Throwable();
 		
@@ -1693,20 +1700,36 @@
 		}
 	}
 
-	private synchronized boolean canHandleAsServerPreparedStatement(String sql) 
+	private boolean canHandleAsServerPreparedStatement(String sql) 
 		throws SQLException {
 		if (sql == null || sql.length() == 0) {
 			return true;
 		}
 
 		if (getCachePreparedStatements()) {
-			Boolean flag = (Boolean)this.serverSideStatementCheckCache.get(sql);
-			
-			if (flag != null) {
-				return flag.booleanValue();
+			synchronized (this.serverSideStatementCheckCache) {
+				Boolean flag = (Boolean)this.serverSideStatementCheckCache.get(sql);
+				
+				if (flag != null) {
+					return flag.booleanValue();
+				}
+					
+				boolean canHandle = canHandleAsServerPreparedStatementNoCache(sql);
+				
+				if (sql.length() < getPreparedStatementCacheSqlLimit()) {
+					this.serverSideStatementCheckCache.put(sql, 
+							canHandle ? Boolean.TRUE : Boolean.FALSE);
+				}
+					
+				return canHandle;
 			}
 		}
 		
+		return canHandleAsServerPreparedStatementNoCache(sql);
+	}
+	
+	private boolean canHandleAsServerPreparedStatementNoCache(String sql) 
+		throws SQLException {
 		boolean canHandleAsStatement = true;
 		
 		if (!versionMeetsMinimum(5, 0, 7) && 
@@ -1776,12 +1799,8 @@
 			canHandleAsStatement = false;
 		}
 
-		if (getCachePreparedStatements() 
-				&& sql.length() < getPreparedStatementCacheSqlLimit()) {
-			this.serverSideStatementCheckCache.put(sql, 
-					canHandleAsStatement ? Boolean.TRUE : Boolean.FALSE);
-		}
 		
+		
 		return canHandleAsStatement;
 	}
 
@@ -2050,54 +2069,56 @@
 	 * @throws SQLException
 	 *             DOCUMENT ME!
 	 */
-	public synchronized PreparedStatement clientPrepareStatement(String sql,
+	public PreparedStatement clientPrepareStatement(String sql,
 			int resultSetType, int resultSetConcurrency) throws SQLException {
 		checkClosed();
 
 		PreparedStatement pStmt = null;
 
 		if (getCachePreparedStatements()) {
-			PreparedStatement.ParseInfo pStmtInfo = (PreparedStatement.ParseInfo) this.cachedPreparedStatementParams
-					.get(sql);
-
-			if (pStmtInfo == null) {
-				pStmt = new com.mysql.jdbc.PreparedStatement(this, 
-						getProcessEscapeCodesForPrepStmts() ? nativeSQL(sql): sql,
-						this.database);
-
-				PreparedStatement.ParseInfo parseInfo = pStmt.getParseInfo();
-
-				if (parseInfo.statementLength < getPreparedStatementCacheSqlLimit()) {
-					if (this.cachedPreparedStatementParams.size() >= getPreparedStatementCacheSize()) {
-						Iterator oldestIter = this.cachedPreparedStatementParams
-								.keySet().iterator();
-						long lruTime = Long.MAX_VALUE;
-						String oldestSql = null;
-
-						while (oldestIter.hasNext()) {
-							String sqlKey = (String) oldestIter.next();
-							PreparedStatement.ParseInfo lruInfo = (PreparedStatement.ParseInfo) this.cachedPreparedStatementParams
-									.get(sqlKey);
-
-							if (lruInfo.lastUsed < lruTime) {
-								lruTime = lruInfo.lastUsed;
-								oldestSql = sqlKey;
+			synchronized (this.cachedPreparedStatementParams) {
+				PreparedStatement.ParseInfo pStmtInfo = (PreparedStatement.ParseInfo) this.cachedPreparedStatementParams
+						.get(sql);
+	
+				if (pStmtInfo == null) {
+					pStmt = new com.mysql.jdbc.PreparedStatement(this, 
+							getProcessEscapeCodesForPrepStmts() ? nativeSQL(sql): sql,
+							this.database);
+	
+					PreparedStatement.ParseInfo parseInfo = pStmt.getParseInfo();
+	
+					if (parseInfo.statementLength < getPreparedStatementCacheSqlLimit()) {
+						if (this.cachedPreparedStatementParams.size() >= getPreparedStatementCacheSize()) {
+							Iterator oldestIter = this.cachedPreparedStatementParams
+									.keySet().iterator();
+							long lruTime = Long.MAX_VALUE;
+							String oldestSql = null;
+	
+							while (oldestIter.hasNext()) {
+								String sqlKey = (String) oldestIter.next();
+								PreparedStatement.ParseInfo lruInfo = (PreparedStatement.ParseInfo) this.cachedPreparedStatementParams
+										.get(sqlKey);
+	
+								if (lruInfo.lastUsed < lruTime) {
+									lruTime = lruInfo.lastUsed;
+									oldestSql = sqlKey;
+								}
 							}
+	
+							if (oldestSql != null) {
+								this.cachedPreparedStatementParams
+										.remove(oldestSql);
+							}
 						}
-
-						if (oldestSql != null) {
-							this.cachedPreparedStatementParams
-									.remove(oldestSql);
-						}
+	
+						this.cachedPreparedStatementParams.put(sql, pStmt
+								.getParseInfo());
 					}
-
-					this.cachedPreparedStatementParams.put(sql, pStmt
-							.getParseInfo());
+				} else {
+					pStmtInfo.lastUsed = System.currentTimeMillis();
+					pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
+							this.database, pStmtInfo);
 				}
-			} else {
-				pStmtInfo.lastUsed = System.currentTimeMillis();
-				pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
-						this.database, pStmtInfo);
 			}
 		} else {
 			pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
@@ -2120,7 +2141,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void close() throws SQLException {
+	public void close() throws SQLException {
 		realClose(true, true, false, null);
 	}
 
@@ -2176,34 +2197,36 @@
 	 *                if a database access error occurs
 	 * @see setAutoCommit
 	 */
-	public synchronized void commit() throws SQLException {
-		checkClosed();
-
-		try {
-			// no-op if _relaxAutoCommit == true
-			if (this.autoCommit && !getRelaxAutoCommit()) {
-				throw SQLError.createSQLException("Can't call commit when autocommit=true");
-			} else if (this.transactionsSupported) {
-				execSQL(null, "commit", -1, null,
-						java.sql.ResultSet.TYPE_FORWARD_ONLY,
-						java.sql.ResultSet.CONCUR_READ_ONLY, false,
-						this.database, true,
-						false);
+	public void commit() throws SQLException {
+		synchronized (getMutex()) {
+			checkClosed();
+	
+			try {
+				// no-op if _relaxAutoCommit == true
+				if (this.autoCommit && !getRelaxAutoCommit()) {
+					throw SQLError.createSQLException("Can't call commit when autocommit=true");
+				} else if (this.transactionsSupported) {
+					execSQL(null, "commit", -1, null,
+							java.sql.ResultSet.TYPE_FORWARD_ONLY,
+							java.sql.ResultSet.CONCUR_READ_ONLY, false,
+							this.database, true,
+							false);
+				}
+			} catch (SQLException sqlException) {
+				if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
+						.equals(sqlException.getSQLState())) {
+					throw SQLError.createSQLException(
+							"Communications link failure during commit(). Transaction resolution unknown.",
+							SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
+				}
+	
+				throw sqlException;
+			} finally {
+				this.needsPing = this.getReconnectAtTxEnd();
 			}
-		} catch (SQLException sqlException) {
-			if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
-					.equals(sqlException.getSQLState())) {
-				throw SQLError.createSQLException(
-						"Communications link failure during commit(). Transaction resolution unknown.",
-						SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
-			}
-
-			throw sqlException;
-		} finally {
-			this.needsPing = this.getReconnectAtTxEnd();
+	
+			return;
 		}
-
-		return;
 	}
 
 	/**
@@ -2851,7 +2874,7 @@
 	 * @throws SQLException
 	 *             passed through from the constructor
 	 */
-	public synchronized java.sql.Statement createStatement() throws SQLException {
+	public java.sql.Statement createStatement() throws SQLException {
 		return createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
 				java.sql.ResultSet.CONCUR_READ_ONLY);
 	}
@@ -2868,7 +2891,7 @@
 	 * @exception SQLException
 	 *                if a database-access error occurs.
 	 */
-	public synchronized java.sql.Statement createStatement(int resultSetType,
+	public java.sql.Statement createStatement(int resultSetType,
 			int resultSetConcurrency) throws SQLException {
 		checkClosed();
 
@@ -2882,7 +2905,7 @@
 	/**
 	 * @see Connection#createStatement(int, int, int)
 	 */
-	public synchronized java.sql.Statement createStatement(int resultSetType,
+	public java.sql.Statement createStatement(int resultSetType,
 			int resultSetConcurrency, int resultSetHoldability)
 			throws SQLException {
 		if (getPedantic()) {
@@ -2943,7 +2966,7 @@
 	// resultSetConcurrency, streamResults, queryIsSelectOnly, catalog,
 	// unpackFields);
 	// }
-	synchronized ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
+	ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
 			Buffer packet, int resultSetType, int resultSetConcurrency,
 			boolean streamResults, String catalog,
 			boolean unpackFields) throws SQLException {
@@ -2952,7 +2975,7 @@
 				catalog, unpackFields, false);
 	}
 
-	synchronized ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
+	ResultSet execSQL(Statement callingStatement, String sql, int maxRows,
 			Buffer packet, int resultSetType, int resultSetConcurrency,
 			boolean streamResults, String catalog,
 			boolean unpackFields,
@@ -3155,9 +3178,13 @@
 		return buf;
 	}
 
-	public synchronized int getActiveStatementCount() {
+	public int getActiveStatementCount() {
+		// Might not have one of these if
+		// not tracking open resources
 		if (this.openStatements != null) {
-			return this.openStatements.size();
+			synchronized (this.openStatements) {
+				return this.openStatements.size();
+			}
 		}
 
 		return 0;
@@ -3171,7 +3198,7 @@
 	 *                if an error occurs
 	 * @see setAutoCommit
 	 */
-	public synchronized boolean getAutoCommit() throws SQLException {
+	public boolean getAutoCommit() throws SQLException {
 		return this.autoCommit;
 	}
 
@@ -3186,7 +3213,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized String getCatalog() throws SQLException {
+	public String getCatalog() throws SQLException {
 		return this.database;
 	}
 
@@ -3205,35 +3232,39 @@
 	 *            the encoding name to retrieve
 	 * @return a character converter, or null if one couldn't be mapped.
 	 */
-	synchronized SingleByteCharsetConverter getCharsetConverter(
+	SingleByteCharsetConverter getCharsetConverter(
 			String javaEncodingName) throws SQLException {
 		if (javaEncodingName == null) {
 			return null;
 		}
 
-		SingleByteCharsetConverter converter = (SingleByteCharsetConverter) this.charsetConverterMap
-				.get(javaEncodingName);
+		SingleByteCharsetConverter converter = null;
+		
+		synchronized (this.charsetConverterMap) {
+			converter = (SingleByteCharsetConverter) this.charsetConverterMap
+			.get(javaEncodingName);
 
-		if (converter == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
-			return null;
-		}
+			if (converter == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
+				return null;
+			}
 
-		if (converter == null) {
-			try {
-				converter = SingleByteCharsetConverter.getInstance(
-						javaEncodingName, this);
+			if (converter == null) {
+				try {
+					converter = SingleByteCharsetConverter.getInstance(
+							javaEncodingName, this);
 
-				if (converter == null) {
+					if (converter == null) {
+						this.charsetConverterMap.put(javaEncodingName,
+								CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
+					}
+
+					this.charsetConverterMap.put(javaEncodingName, converter);
+				} catch (UnsupportedEncodingException unsupEncEx) {
 					this.charsetConverterMap.put(javaEncodingName,
 							CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
+
+					converter = null;
 				}
-
-				this.charsetConverterMap.put(javaEncodingName, converter);
-			} catch (UnsupportedEncodingException unsupEncEx) {
-				this.charsetConverterMap.put(javaEncodingName,
-						CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
-
-				converter = null;
 			}
 		}
 
@@ -3363,44 +3394,45 @@
 		return this.maxAllowedPacket;
 	}
 
-	protected synchronized int getMaxBytesPerChar(String javaCharsetName)
+	protected int getMaxBytesPerChar(String javaCharsetName)
 			throws SQLException {
 		// TODO: Check if we can actually run this query at this point in time
 		String charset = CharsetMapping.getMysqlEncodingForJavaEncoding(
 				javaCharsetName, this);
 
 		if (versionMeetsMinimum(4, 1, 0)) {
-			if (this.charsetToNumBytesMap == null) {
-				this.charsetToNumBytesMap = new HashMap();
-
-				java.sql.Statement stmt = null;
-				java.sql.ResultSet rs = null;
-
-				try {
-					stmt = getMetadataSafeStatement();
-
-					rs = stmt.executeQuery("SHOW CHARACTER SET");
-
-					while (rs.next()) {
-						this.charsetToNumBytesMap.put(rs.getString("Charset"),
-								new Integer(rs.getInt("Maxlen")));
-					}
-
-					rs.close();
-					rs = null;
-
-					stmt.close();
-
-					stmt = null;
-				} finally {
-					if (rs != null) {
+			synchronized (this.charsetToNumBytesMap) {
+				if (this.charsetToNumBytesMap.isEmpty()) {
+					
+					java.sql.Statement stmt = null;
+					java.sql.ResultSet rs = null;
+	
+					try {
+						stmt = getMetadataSafeStatement();
+	
+						rs = stmt.executeQuery("SHOW CHARACTER SET");
+	
+						while (rs.next()) {
+							this.charsetToNumBytesMap.put(rs.getString("Charset"),
+									new Integer(rs.getInt("Maxlen")));
+						}
+	
 						rs.close();
 						rs = null;
-					}
-
-					if (stmt != null) {
+	
 						stmt.close();
+	
 						stmt = null;
+					} finally {
+						if (rs != null) {
+							rs.close();
+							rs = null;
+						}
+	
+						if (stmt != null) {
+							stmt.close();
+							stmt = null;
+						}
 					}
 				}
 			}
@@ -3594,7 +3626,9 @@
 			}
 		}
 
-		return this.isolationLevel;
+		synchronized (this) {
+			return this.isolationLevel;
+		}
 	}
 
 	/**
@@ -3975,7 +4009,7 @@
 	 * 
 	 * @return DOCUMENT ME!
 	 */
-	public synchronized boolean isClosed() {
+	public boolean isClosed() {
 		return this.isClosed;
 	}
 	
@@ -4196,7 +4230,7 @@
 	 * @throws SQLException
 	 *             DOCUMENT ME!
 	 */
-	public synchronized java.sql.CallableStatement prepareCall(String sql)
+	public java.sql.CallableStatement prepareCall(String sql)
 			throws SQLException {
 		if (this.getUseUltraDevWorkAround()) {
 			return new UltraDevWorkAround(prepareStatement(sql));
@@ -4221,7 +4255,7 @@
 	 * @exception SQLException
 	 *                if a database-access error occurs.
 	 */
-	public synchronized java.sql.CallableStatement prepareCall(String sql,
+	public java.sql.CallableStatement prepareCall(String sql,
 			int resultSetType, int resultSetConcurrency) throws SQLException {
 		if (versionMeetsMinimum(5, 0, 0)) {
 			CallableStatement cStmt = null;
@@ -4230,25 +4264,22 @@
 
 				cStmt = parseCallableStatement(sql);
 			} else {
-				if (this.parsedCallableStatementCache == null) {
-					this.parsedCallableStatementCache = new LRUCache(
-							getCallableStatementCacheSize());
+				synchronized (this.parsedCallableStatementCache) {
+					CompoundCacheKey key = new CompoundCacheKey(getCatalog(), sql);
+	
+					CallableStatement.CallableStatementParamInfo cachedParamInfo = (CallableStatement.CallableStatementParamInfo) this.parsedCallableStatementCache
+							.get(key);
+	
+					if (cachedParamInfo != null) {
+						cStmt = new CallableStatement(this, cachedParamInfo);
+					} else {
+						cStmt = parseCallableStatement(sql);
+	
+						cachedParamInfo = cStmt.paramInfo;
+	
+						this.parsedCallableStatementCache.put(key, cachedParamInfo);
+					}
 				}
-
-				CompoundCacheKey key = new CompoundCacheKey(getCatalog(), sql);
-
-				CallableStatement.CallableStatementParamInfo cachedParamInfo = (CallableStatement.CallableStatementParamInfo) this.parsedCallableStatementCache
-						.get(key);
-
-				if (cachedParamInfo != null) {
-					cStmt = new CallableStatement(this, cachedParamInfo);
-				} else {
-					cStmt = parseCallableStatement(sql);
-
-					cachedParamInfo = cStmt.paramInfo;
-
-					this.parsedCallableStatementCache.put(key, cachedParamInfo);
-				}
 			}
 
 			cStmt.setResultSetType(resultSetType);
@@ -4264,7 +4295,7 @@
 	/**
 	 * @see Connection#prepareCall(String, int, int, int)
 	 */
-	public synchronized java.sql.CallableStatement prepareCall(String sql,
+	public java.sql.CallableStatement prepareCall(String sql,
 			int resultSetType, int resultSetConcurrency,
 			int resultSetHoldability) throws SQLException {
 		if (getPedantic()) {
@@ -4306,7 +4337,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs.
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql)
+	public java.sql.PreparedStatement prepareStatement(String sql)
 			throws SQLException {
 		return prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY,
 				java.sql.ResultSet.CONCUR_READ_ONLY);
@@ -4315,7 +4346,7 @@
 	/**
 	 * @see Connection#prepareStatement(String, int)
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql,
+	public java.sql.PreparedStatement prepareStatement(String sql,
 			int autoGenKeyIndex) throws SQLException {
 		java.sql.PreparedStatement pStmt = prepareStatement(sql);
 
@@ -4340,7 +4371,7 @@
 	 * @exception SQLException
 	 *                if a database-access error occurs.
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql,
+	public java.sql.PreparedStatement prepareStatement(String sql,
 			int resultSetType, int resultSetConcurrency) throws SQLException {
 		checkClosed();
 
@@ -4360,31 +4391,43 @@
 		
 		if (this.useServerPreparedStmts && canServerPrepare) {
 			if (this.getCachePreparedStatements()) {
-				pStmt = (com.mysql.jdbc.ServerPreparedStatement)this.serverSideStatementCache.remove(sql);
-				
-				if (pStmt != null) {
-					pStmt.clearParameters();
-					((com.mysql.jdbc.ServerPreparedStatement)pStmt).setClosed(false);
+				synchronized (this.serverSideStatementCache) {
+					pStmt = (com.mysql.jdbc.ServerPreparedStatement)this.serverSideStatementCache.remove(sql);
+					
+					if (pStmt != null) {
+						pStmt.clearParameters();
+						((com.mysql.jdbc.ServerPreparedStatement)pStmt).setClosed(false);
+					}
+
+					if (pStmt == null) {
+						try {
+							pStmt = new com.mysql.jdbc.ServerPreparedStatement(this, nativeSql,
+									this.database);
+							if (sql.length() < getPreparedStatementCacheSqlLimit()) {
+								((com.mysql.jdbc.ServerPreparedStatement)pStmt).isCached = true;
+							}
+						} catch (SQLException sqlEx) {
+							// Punt, if necessary
+							if (getEmulateUnsupportedPstmts()) {
+								pStmt = clientPrepareStatement(nativeSql);
+								
+								if (sql.length() < getPreparedStatementCacheSqlLimit()) {
+									this.serverSideStatementCheckCache.put(sql, Boolean.FALSE);
+								}
+							} else {
+								throw sqlEx;
+							}
+						}
+					}
 				}
-			}
-			
-			if (pStmt == null) {
+			} else {
 				try {
 					pStmt = new com.mysql.jdbc.ServerPreparedStatement(this, nativeSql,
 							this.database);
-					if (this.getCachePreparedStatements() 
-							&& sql.length() < getPreparedStatementCacheSqlLimit()) {
-						((com.mysql.jdbc.ServerPreparedStatement)pStmt).isCached = true;
-					}
 				} catch (SQLException sqlEx) {
 					// Punt, if necessary
 					if (getEmulateUnsupportedPstmts()) {
 						pStmt = clientPrepareStatement(nativeSql);
-						
-						if (getCachePreparedStatements() 
-								&& sql.length() < getPreparedStatementCacheSqlLimit()) {
-							this.serverSideStatementCheckCache.put(sql, Boolean.FALSE);
-						}
 					} else {
 						throw sqlEx;
 					}
@@ -4404,7 +4447,7 @@
 	/**
 	 * @see Connection#prepareStatement(String, int, int, int)
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql,
+	public java.sql.PreparedStatement prepareStatement(String sql,
 			int resultSetType, int resultSetConcurrency,
 			int resultSetHoldability) throws SQLException {
 		if (getPedantic()) {
@@ -4421,7 +4464,7 @@
 	/**
 	 * @see Connection#prepareStatement(String, int[])
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql,
+	public java.sql.PreparedStatement prepareStatement(String sql,
 			int[] autoGenKeyIndexes) throws SQLException {
 		java.sql.PreparedStatement pStmt = prepareStatement(sql);
 
@@ -4435,7 +4478,7 @@
 	/**
 	 * @see Connection#prepareStatement(String, String[])
 	 */
-	public synchronized java.sql.PreparedStatement prepareStatement(String sql,
+	public java.sql.PreparedStatement prepareStatement(String sql,
 			String[] autoGenKeyColNames) throws SQLException {
 		java.sql.PreparedStatement pStmt = prepareStatement(sql);
 
@@ -4561,8 +4604,10 @@
 	 * @param stmt
 	 *            the Statement instance to remove
 	 */
-	synchronized void registerStatement(Statement stmt) {
-		this.openStatements.put(stmt, stmt);
+	void registerStatement(Statement stmt) {
+		synchronized (this.openStatements) {
+			this.openStatements.put(stmt, stmt);
+		}
 	}
 
 	/**
@@ -4806,36 +4851,38 @@
 	 * @see commit
 	 */
 	public void rollback() throws SQLException {
-		checkClosed();
-
-		try {
-			// no-op if _relaxAutoCommit == true
-			if (this.autoCommit && !getRelaxAutoCommit()) {
-				throw SQLError.createSQLException(
-						"Can't call rollback when autocommit=true",
-						SQLError.SQL_STATE_CONNECTION_NOT_OPEN);
-			} else if (this.transactionsSupported) {
-				try {
-					rollbackNoChecks();
-				} catch (SQLException sqlEx) {
-					// We ignore non-transactional tables if told to do so
-					if (getIgnoreNonTxTables()
-							&& (sqlEx.getErrorCode() != SQLError.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
-						throw sqlEx;
+		synchronized (getMutex()) {
+			checkClosed();
+	
+			try {
+				// no-op if _relaxAutoCommit == true
+				if (this.autoCommit && !getRelaxAutoCommit()) {
+					throw SQLError.createSQLException(
+							"Can't call rollback when autocommit=true",
+							SQLError.SQL_STATE_CONNECTION_NOT_OPEN);
+				} else if (this.transactionsSupported) {
+					try {
+						rollbackNoChecks();
+					} catch (SQLException sqlEx) {
+						// We ignore non-transactional tables if told to do so
+						if (getIgnoreNonTxTables()
+								&& (sqlEx.getErrorCode() != SQLError.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
+							throw sqlEx;
+						}
 					}
 				}
+			} catch (SQLException sqlException) {
+				if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
+						.equals(sqlException.getSQLState())) {
+					throw SQLError.createSQLException(
+							"Communications link failure during rollback(). Transaction resolution unknown.",
+							SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
+				}
+	
+				throw sqlException;
+			} finally {
+				this.needsPing = this.getReconnectAtTxEnd();
 			}
-		} catch (SQLException sqlException) {
-			if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
-					.equals(sqlException.getSQLState())) {
-				throw SQLError.createSQLException(
-						"Communications link failure during rollback(). Transaction resolution unknown.",
-						SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
-			}
-
-			throw sqlException;
-		} finally {
-			this.needsPing = this.getReconnectAtTxEnd();
 		}
 	}
 
@@ -4845,79 +4892,67 @@
 	public void rollback(Savepoint savepoint) throws SQLException {
 
 		if (versionMeetsMinimum(4, 0, 14) || versionMeetsMinimum(4, 1, 1)) {
-			checkClosed();
-
-			try {
-				StringBuffer rollbackQuery = new StringBuffer(
-						"ROLLBACK TO SAVEPOINT ");
-				rollbackQuery.append('`');
-				rollbackQuery.append(savepoint.getSavepointName());
-				rollbackQuery.append('`');
-
-				java.sql.Statement stmt = null;
-
+			synchronized (getMutex()) {
+				checkClosed();
+	
 				try {
-					stmt = createStatement();
-
-					stmt.executeUpdate(rollbackQuery.toString());
-				} catch (SQLException sqlEx) {
-					int errno = sqlEx.getErrorCode();
-
-					if (errno == 1181) {
-						String msg = sqlEx.getMessage();
-
-						if (msg != null) {
-							int indexOfError153 = msg.indexOf("153");
-
-							if (indexOfError153 != -1) {
-								throw SQLError.createSQLException("Savepoint '"
-										+ savepoint.getSavepointName()
-										+ "' does not exist",
-										SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
-										errno);
+					StringBuffer rollbackQuery = new StringBuffer(
+							"ROLLBACK TO SAVEPOINT ");
+					rollbackQuery.append('`');
+					rollbackQuery.append(savepoint.getSavepointName());
+					rollbackQuery.append('`');
+	
+					java.sql.Statement stmt = null;
+	
+					try {
+						stmt = createStatement();
+	
+						stmt.executeUpdate(rollbackQuery.toString());
+					} catch (SQLException sqlEx) {
+						int errno = sqlEx.getErrorCode();
+	
+						if (errno == 1181) {
+							String msg = sqlEx.getMessage();
+	
+							if (msg != null) {
+								int indexOfError153 = msg.indexOf("153");
+	
+								if (indexOfError153 != -1) {
+									throw SQLError.createSQLException("Savepoint '"
+											+ savepoint.getSavepointName()
+											+ "' does not exist",
+											SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
+											errno);
+								}
 							}
 						}
-					}
-
-					// We ignore non-transactional tables if told to do so
-					if (getIgnoreNonTxTables()
-							&& (sqlEx.getErrorCode() != SQLError.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
+	
+						// We ignore non-transactional tables if told to do so
+						if (getIgnoreNonTxTables()
+								&& (sqlEx.getErrorCode() != SQLError.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
+							throw sqlEx;
+						}
+	
+						if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
+								.equals(sqlEx.getSQLState())) {
+							throw SQLError.createSQLException(
+									"Communications link failure during rollback(). Transaction resolution unknown.",
+									SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
+						}
+	
 						throw sqlEx;
+					} finally {
+						closeStatement(stmt);
 					}
-
-					if (SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE
-							.equals(sqlEx.getSQLState())) {
-						throw SQLError.createSQLException(
-								"Communications link failure during rollback(). Transaction resolution unknown.",
-								SQLError.SQL_STATE_TRANSACTION_RESOLUTION_UNKNOWN);
-					}
-
-					throw sqlEx;
 				} finally {
-					if (stmt != null) {
-						try {
-							stmt.close();
-						} catch (SQLException sqlEx) {
-							; // ignore
-						}
-
-						stmt = null;
-					}
+					this.needsPing = this.getReconnectAtTxEnd();
 				}
-			} finally {
-				this.needsPing = this.getReconnectAtTxEnd();
 			}
 		} else {
 			throw new NotImplemented();
 		}
 	}
 
-	// *********************************************************************
-	//
-	// END OF PUBLIC INTERFACE
-	//
-	// *********************************************************************
-
 	private void rollbackNoChecks() throws SQLException {
 		execSQL(null, "rollback", -1, null,
 				java.sql.ResultSet.TYPE_FORWARD_ONLY,
@@ -4965,59 +5000,61 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void setAutoCommit(boolean autoCommitFlag) throws SQLException {
-		checkClosed();
-
-		if (getAutoReconnectForPools()) {
-			setHighAvailability(true);
-		}
-
-		try {
-			if (this.transactionsSupported) {
-
-				boolean needsSetOnServer = true;
-
-				if (this.getUseLocalSessionState()
-						&& this.autoCommit == autoCommitFlag) {
-					needsSetOnServer = false;
-				} else if (!this.getHighAvailability()) {
-					needsSetOnServer = this.getIO()
-							.isSetNeededForAutoCommitMode(autoCommitFlag);
+	public void setAutoCommit(boolean autoCommitFlag) throws SQLException {
+		synchronized (getMutex()) {
+			checkClosed();
+	
+			if (getAutoReconnectForPools()) {
+				setHighAvailability(true);
+			}
+	
+			try {
+				if (this.transactionsSupported) {
+	
+					boolean needsSetOnServer = true;
+	
+					if (this.getUseLocalSessionState()
+							&& this.autoCommit == autoCommitFlag) {
+						needsSetOnServer = false;
+					} else if (!this.getHighAvailability()) {
+						needsSetOnServer = this.getIO()
+								.isSetNeededForAutoCommitMode(autoCommitFlag);
+					}
+	
+					// this internal value must be set first as failover depends on
+					// it
+					// being set to true to fail over (which is done by most
+					// app servers and connection pools at the end of
+					// a transaction), and the driver issues an implicit set
+					// based on this value when it (re)-connects to a server
+					// so the value holds across connections
+					this.autoCommit = autoCommitFlag;
+	
+					if (needsSetOnServer) {
+						execSQL(null, autoCommitFlag ? "SET autocommit=1"
+								: "SET autocommit=0", -1, null,
+								java.sql.ResultSet.TYPE_FORWARD_ONLY,
+								java.sql.ResultSet.CONCUR_READ_ONLY, false,
+								this.database, true, false);
+					}
+	
+				} else {
+					if ((autoCommitFlag == false) && !getRelaxAutoCommit()) {
+						throw SQLError.createSQLException("MySQL Versions Older than 3.23.15 "
+								+ "do not support transactions",
+								SQLError.SQL_STATE_CONNECTION_NOT_OPEN);
+					}
+	
+					this.autoCommit = autoCommitFlag;
 				}
-
-				// this internal value must be set first as failover depends on
-				// it
-				// being set to true to fail over (which is done by most
-				// app servers and connection pools at the end of
-				// a transaction), and the driver issues an implicit set
-				// based on this value when it (re)-connects to a server
-				// so the value holds across connections
-				this.autoCommit = autoCommitFlag;
-
-				if (needsSetOnServer) {
-					execSQL(null, autoCommitFlag ? "SET autocommit=1"
-							: "SET autocommit=0", -1, null,
-							java.sql.ResultSet.TYPE_FORWARD_ONLY,
-							java.sql.ResultSet.CONCUR_READ_ONLY, false,
-							this.database, true, false);
+			} finally {
+				if (this.getAutoReconnectForPools()) {
+					setHighAvailability(false);
 				}
-
-			} else {
-				if ((autoCommitFlag == false) && !getRelaxAutoCommit()) {
-					throw SQLError.createSQLException("MySQL Versions Older than 3.23.15 "
-							+ "do not support transactions",
-							SQLError.SQL_STATE_CONNECTION_NOT_OPEN);
-				}
-
-				this.autoCommit = autoCommitFlag;
 			}
-		} finally {
-			if (this.getAutoReconnectForPools()) {
-				setHighAvailability(false);
-			}
+	
+			return;
 		}
-
-		return;
 	}
 
 	/**
@@ -5033,42 +5070,45 @@
 	 * @throws SQLException
 	 *             if a database access error occurs
 	 */
-	public synchronized void setCatalog(String catalog) throws SQLException {
-		checkClosed();
-
-		if (catalog == null) {
-			throw SQLError.createSQLException("Catalog can not be null",
-					SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
-		}
-		
-		if (getUseLocalSessionState()) {
-			if (this.lowerCaseTableNames) {
-				if (this.database.equalsIgnoreCase(catalog)) {
-					return;
+	public void setCatalog(String catalog) throws SQLException {
+		synchronized (getMutex()) {
+			checkClosed();
+	
+			if (catalog == null) {
+				throw SQLError.createSQLException("Catalog can not be null",
+						SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
+			}
+			
+			if (getUseLocalSessionState()) {
+				if (this.lowerCaseTableNames) {
+					if (this.database.equalsIgnoreCase(catalog)) {
+						return;
+					}
+				} else {
+					if (this.database.equals(catalog)) {
+						return;
+					}
 				}
-			} else {
-				if (this.database.equals(catalog)) {
-					return;
-				}
 			}
+			
+			String quotedId = this.dbmd.getIdentifierQuoteString();
+	
+			if ((quotedId == null) || quotedId.equals(" ")) {
+				quotedId = "";
+			}
+	
+			StringBuffer query = new StringBuffer("USE ");
+			query.append(quotedId);
+			query.append(catalog);
+			query.append(quotedId);
+	
+			execSQL(null, query.toString(), -1, null,
+					java.sql.ResultSet.TYPE_FORWARD_ONLY,
+					java.sql.ResultSet.CONCUR_READ_ONLY, false,
+					this.database, true, false);
+			
+			this.database = catalog;
 		}
-		
-		String quotedId = this.dbmd.getIdentifierQuoteString();
-
-		if ((quotedId == null) || quotedId.equals(" ")) {
-			quotedId = "";
-		}
-
-		StringBuffer query = new StringBuffer("USE ");
-		query.append(quotedId);
-		query.append(catalog);
-		query.append(quotedId);
-
-		execSQL(null, query.toString(), -1, null,
-				java.sql.ResultSet.TYPE_FORWARD_ONLY,
-				java.sql.ResultSet.CONCUR_READ_ONLY, false,
-				this.database, true, false);
-		this.database = catalog;
 	}
 
 	/**
@@ -5125,7 +5165,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void setReadOnly(boolean readOnlyFlag) throws SQLException {
+	public void setReadOnly(boolean readOnlyFlag) throws SQLException {
 		checkClosed();
 		this.readOnly = readOnlyFlag;
 	}
@@ -5133,7 +5173,7 @@
 	/**
 	 * @see Connection#setSavepoint()
 	 */
-	public synchronized java.sql.Savepoint setSavepoint() throws SQLException {
+	public java.sql.Savepoint setSavepoint() throws SQLException {
 		MysqlSavepoint savepoint = new MysqlSavepoint();
 
 		setSavepoint(savepoint);
@@ -5144,28 +5184,22 @@
 	private void setSavepoint(MysqlSavepoint savepoint) throws SQLException {
 
 		if (versionMeetsMinimum(4, 0, 14) || versionMeetsMinimum(4, 1, 1)) {
-			checkClosed();
-
-			StringBuffer savePointQuery = new StringBuffer("SAVEPOINT ");
-			savePointQuery.append('`');
-			savePointQuery.append(savepoint.getSavepointName());
-			savePointQuery.append('`');
-
-			java.sql.Statement stmt = null;
-
-			try {
-				stmt = createStatement();
-
-				stmt.executeUpdate(savePointQuery.toString());
-			} finally {
-				if (stmt != null) {
-					try {
-						stmt.close();
-					} catch (SQLException sqlEx) {
-						; // ignore
-					}
-
-					stmt = null;
+			synchronized (getMutex()) {
+				checkClosed();
+	
+				StringBuffer savePointQuery = new StringBuffer("SAVEPOINT ");
+				savePointQuery.append('`');
+				savePointQuery.append(savepoint.getSavepointName());
+				savePointQuery.append('`');
+	
+				java.sql.Statement stmt = null;
+	
+				try {
+					stmt = createStatement();
+	
+					stmt.executeUpdate(savePointQuery.toString());
+				} finally {
+					closeStatement(stmt);
 				}
 			}
 		} else {
@@ -5173,6 +5207,18 @@
 		}
 	}
 
+	private void closeStatement(java.sql.Statement stmt) {
+		if (stmt != null) {
+			try {
+				stmt.close();
+			} catch (SQLException sqlEx) {
+				; // ignore
+			}
+
+			stmt = null;
+		}
+	}
+
 	/**
 	 * @see Connection#setSavepoint(String)
 	 */
@@ -5368,9 +5414,11 @@
 	 * @param stmt
 	 *            the Statement instance to remove
 	 */
-	synchronized void unregisterStatement(Statement stmt) {
+	void unregisterStatement(Statement stmt) {
 		if (this.openStatements != null) {
-			this.openStatements.remove(stmt);
+			synchronized (this.openStatements) {
+				this.openStatements.remove(stmt);
+			}
 		}
 	}
 
@@ -5417,8 +5465,10 @@
 		}
 	}
 
-	protected synchronized void recachePreparedStatement(ServerPreparedStatement pstmt) {
-		this.serverSideStatementCache.put(pstmt.originalSql, pstmt);
+	protected void recachePreparedStatement(ServerPreparedStatement pstmt) {
+		synchronized (this.serverSideStatementCache) {
+			this.serverSideStatementCache.put(pstmt.originalSql, pstmt);
+		}
 	}
 	
 	public boolean versionMeetsMinimum(int major, int minor, int subminor)
@@ -5495,7 +5545,7 @@
 	 * Optimization to only use one calendar per-session, or calculate it for
 	 * each call, depending on user configuration
 	 */
-	protected synchronized Calendar getCalendarInstanceForSessionOrNew() {
+	protected Calendar getCalendarInstanceForSessionOrNew() {
 		if (getDynamicCalendars()) {
 			return Calendar.getInstance();
 		}
@@ -5503,12 +5553,12 @@
 		return getSessionLockedCalendar();
 	}
 	
-	protected synchronized Calendar getSessionLockedCalendar() {
+	protected Calendar getSessionLockedCalendar() {
 	
 		return this.sessionCalendar;
 	}
 	
-	protected synchronized Calendar getUtcCalendar() {
+	protected Calendar getUtcCalendar() {
 		return this.utcCalendar;
 	}
 

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java	2006-04-04 00:03:07 UTC (rev 5132)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSet.java	2006-04-04 15:53:24 UTC (rev 5133)
@@ -321,7 +321,10 @@
 	public ResultSet(String catalog, Field[] fields, RowData tuples,
 			Connection conn, Statement creatorStmt) throws SQLException {
 		this.connection = conn;
-
+		
+		this.fastDateCal = new GregorianCalendar(Locale.US);
+		this.fastDateCal.setTimeZone(this.getDefaultTimeZone());
+		
 		if (this.connection != null) {
 			this.useStrictFloatingPoint = this.connection
 					.getStrictFloatingPoint();
@@ -494,24 +497,6 @@
 	}
 
 	/**
-	 * @param truncation
-	 */
-	private synchronized void addAWarning(SQLWarning warning) {
-		if (this.warningChain == null) {
-			this.warningChain = warning;
-		} else {
-			SQLWarning warningToAppendTo = this.warningChain;
-
-			while (warningToAppendTo.getNextWarning() != null) {
-				warningToAppendTo = warningToAppendTo.getNextWarning();
-			}
-
-			warningToAppendTo.setNextWarning(warning);
-		}
-
-	}
-
-	/**
 	 * JDBC 2.0
 	 * 
 	 * <p>
@@ -641,7 +626,7 @@
 	 * @throws SQLException
 	 *             if the result set is closed
 	 */
-	protected final synchronized void checkClosed() throws SQLException {
+	protected final void checkClosed() throws SQLException {
 		if (this.isClosed) {
 			throw SQLError.createSQLException(
 					Messages
@@ -739,7 +724,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void close() throws SQLException {
+	public void close() throws SQLException {
 		realClose(true);
 	}
 
@@ -854,14 +839,9 @@
 		return stringVal;
 	}
 
-	private synchronized Date fastDateCreate(Calendar cal, int year, int month,
+	private Date fastDateCreate(Calendar cal, int year, int month,
 			int day) {
 		if (cal == null) {
-			if (this.fastDateCal == null) {
-				this.fastDateCal = new GregorianCalendar(Locale.US);
-				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());
-			}
-
 			cal = this.fastDateCal;
 		}
 
@@ -872,29 +852,19 @@
 				cal, year, month, day);
 	}
 
-	private synchronized Time fastTimeCreate(Calendar cal, int hour,
+	private Time fastTimeCreate(Calendar cal, int hour,
 			int minute, int second) {
 		if (cal == null) {
-			if (this.fastDateCal == null) {
-				this.fastDateCal = new GregorianCalendar(Locale.US);
-				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());
-			}
-
 			cal = this.fastDateCal;
 		}
 
 		return TimeUtil.fastTimeCreate(cal, hour, minute, second);
 	}
 
-	private synchronized Timestamp fastTimestampCreate(Calendar cal, int year,
+	private Timestamp fastTimestampCreate(Calendar cal, int year,
 			int month, int day, int hour, int minute, int seconds,
 			int secondsPart) {
 		if (cal == null) {
-			if (this.fastDateCal == null) {
-				this.fastDateCal = new GregorianCalendar(Locale.US);
-				this.fastDateCal.setTimeZone(this.getDefaultTimeZone());
-			}
-
 			cal = this.fastDateCal;
 		}
 
@@ -1689,7 +1659,7 @@
 	 * Optimization to only use one calendar per-session, or calculate it for
 	 * each call, depending on user configuration
 	 */
-	private synchronized Calendar getCalendarInstanceForSessionOrNew() {
+	private Calendar getCalendarInstanceForSessionOrNew() {
 		if (this.connection != null) {
 			return this.connection.getCalendarInstanceForSessionOrNew();
 		} else {
@@ -2089,7 +2059,9 @@
 		}
 	}
 
-	private synchronized TimeZone getDefaultTimeZone() {
+	private TimeZone getDefaultTimeZone() {
+		// Worst case we allocate this twice and the other gets GC'd,
+		// however prevents deadlock
 		if (this.defaultTimeZone == null) {
 			this.defaultTimeZone = TimeZone.getDefault();
 		}
@@ -8101,8 +8073,10 @@
 		return this.wasNullFlag;
 	}
 
-	protected synchronized Calendar getGmtCalendar() {
+	protected Calendar getGmtCalendar() {
 		
+		// Worst case we allocate this twice and the other gets GC'd,
+		// however prevents deadlock
 		if (this.gmtCalendar == null) {
 			this.gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
 		}
@@ -8110,7 +8084,7 @@
 		return this.gmtCalendar;
 	}
 	
-		private Object getNativeDateTimeValue(int columnIndex, Calendar targetCalendar,
+	private Object getNativeDateTimeValue(int columnIndex, Calendar targetCalendar,
 				int jdbcType,
 			int mysqlType, TimeZone tz, boolean rollForward)
 			throws SQLException {

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-04-04 00:03:07 UTC (rev 5132)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-04-04 15:53:24 UTC (rev 5133)
@@ -423,7 +423,7 @@
 	/**
 	 * @see java.sql.PreparedStatement#clearParameters()
 	 */
-	public synchronized void clearParameters() throws SQLException {
+	public void clearParameters() throws SQLException {
 		checkClosed();
 		clearParametersInternal(true);
 	}
@@ -783,7 +783,7 @@
 	/**
 	 * @see com.mysql.jdbc.PreparedStatement#getBytes(int)
 	 */
-	synchronized byte[] getBytes(int parameterIndex) throws SQLException {
+	byte[] getBytes(int parameterIndex) throws SQLException {
 		BindValue bindValue = getBinding(parameterIndex, false);
 
 		if (bindValue.isNull) {
@@ -831,7 +831,7 @@
 	/**
 	 * @see java.sql.PreparedStatement#getParameterMetaData()
 	 */
-	public synchronized ParameterMetaData getParameterMetaData() throws SQLException {
+	public ParameterMetaData getParameterMetaData() throws SQLException {
 		checkClosed();
 		
 		if (this.parameterMetaData == null) {
@@ -859,7 +859,7 @@
 	 * @throws SQLException
 	 *             if an error occurs
 	 */
-	protected synchronized void realClose(boolean calledExplicitly, 
+	protected void realClose(boolean calledExplicitly, 
 			boolean closeOpenResults) throws SQLException {
 		if (this.isClosed) {
 			return;

Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2006-04-04 00:03:07 UTC (rev 5132)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Statement.java	2006-04-04 15:53:24 UTC (rev 5133)
@@ -452,7 +452,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs (why?)
 	 */
-	public synchronized void clearWarnings() throws SQLException {
+	public void clearWarnings() throws SQLException {
 		this.warningChain = null;
 	}
 
@@ -471,7 +471,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void close() throws SQLException {
+	public void close() throws SQLException {
 		realClose(true, true);
 	}
 
@@ -559,56 +559,57 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized boolean execute(String sql) throws SQLException {
-		this.wasCancelled = false;
-
-		checkNullOrEmptyQuery(sql);
-
-		checkClosed();
-
-		char firstNonWsChar = StringUtils.firstNonWsCharUc(sql);
-
-		boolean isSelect = true;
-
-		if (firstNonWsChar != 'S') {
-			isSelect = false;
-
-			if (this.connection.isReadOnly()) {
-				throw SQLError.createSQLException(Messages
-						.getString("Statement.27") //$NON-NLS-1$
-						+ Messages.getString("Statement.28"), //$NON-NLS-1$
-						SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
+	public boolean execute(String sql) throws SQLException {
+		synchronized (this.connection.getMutex()) {
+			this.wasCancelled = false;
+	
+			checkNullOrEmptyQuery(sql);
+	
+			checkClosed();
+	
+			char firstNonWsChar = StringUtils.firstNonWsCharUc(sql);
+	
+			boolean isSelect = true;
+	
+			if (firstNonWsChar != 'S') {
+				isSelect = false;
+	
+				if (this.connection.isReadOnly()) {
+					throw SQLError.createSQLException(Messages
+							.getString("Statement.27") //$NON-NLS-1$
+							+ Messages.getString("Statement.28"), //$NON-NLS-1$
+							SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
+				}
 			}
-		}
-
-		if (this.doEscapeProcessing) {
-			Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-					this.connection.serverSupportsConvertFn(), this.connection);
-
-			if (escapedSqlResult instanceof String) {
-				sql = (String) escapedSqlResult;
-			} else {
-				sql = ((EscapeProcessorResult) escapedSqlResult).escapedSql;
+	
+			if (this.doEscapeProcessing) {
+				Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
+						this.connection.serverSupportsConvertFn(), this.connection);
+	
+				if (escapedSqlResult instanceof String) {
+					sql = (String) escapedSqlResult;
+				} else {
+					sql = ((EscapeProcessorResult) escapedSqlResult).escapedSql;
+				}
 			}
-		}
-
-		if (this.results != null) {
-			if (!this.connection.getHoldResultsOpenOverStatementClose()) {
-				this.results.realClose(false);
+	
+			if (this.results != null) {
+				if (!this.connection.getHoldResultsOpenOverStatementClose()) {
+					this.results.realClose(false);
+				}
 			}
-		}
-
-		CachedResultSetMetaData cachedMetaData = null;
-
-		ResultSet rs = null;
-
-		// If there isn't a limit clause in the SQL
-		// then limit the number of rows to return in
-		// an efficient manner. Only do this if
-		// setMaxRows() hasn't been used on any Statements
-		// generated from the current Connection (saves
-		// a query, and network traffic).
-		synchronized (this.connection.getMutex()) {
+	
+			CachedResultSetMetaData cachedMetaData = null;
+	
+			ResultSet rs = null;
+	
+			// If there isn't a limit clause in the SQL
+			// then limit the number of rows to return in
+			// an efficient manner. Only do this if
+			// setMaxRows() hasn't been used on any Statements
+			// generated from the current Connection (saves
+			// a query, and network traffic).
+			
 			this.batchedGeneratedKeys = null;
 			
 			if (useServerFetch()) {
@@ -1026,44 +1027,45 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized java.sql.ResultSet executeQuery(String sql)
+	public java.sql.ResultSet executeQuery(String sql)
 			throws SQLException {
-		this.wasCancelled = false;
-
-		checkNullOrEmptyQuery(sql);
-
-		checkClosed();
-
-		if (this.doEscapeProcessing) {
-			Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
-					this.connection.serverSupportsConvertFn(), this.connection);
-
-			if (escapedSqlResult instanceof String) {
-				sql = (String) escapedSqlResult;
-			} else {
-				sql = ((EscapeProcessorResult) escapedSqlResult).escapedSql;
+		synchronized (this.connection.getMutex()) {
+			this.wasCancelled = false;
+	
+			checkNullOrEmptyQuery(sql);
+	
+			checkClosed();
+	
+			if (this.doEscapeProcessing) {
+				Object escapedSqlResult = EscapeProcessor.escapeSQL(sql,
+						this.connection.serverSupportsConvertFn(), this.connection);
+	
+				if (escapedSqlResult instanceof String) {
+					sql = (String) escapedSqlResult;
+				} else {
+					sql = ((EscapeProcessorResult) escapedSqlResult).escapedSql;
+				}
 			}
-		}
-
-		char firstStatementChar = StringUtils.firstNonWsCharUc(sql);
-
-		checkForDml(sql, firstStatementChar);
-
-		if (this.results != null) {
-			if (!this.connection.getHoldResultsOpenOverStatementClose()) {
-				this.results.realClose(false);
+	
+			char firstStatementChar = StringUtils.firstNonWsCharUc(sql);
+	
+			checkForDml(sql, firstStatementChar);
+	
+			if (this.results != null) {
+				if (!this.connection.getHoldResultsOpenOverStatementClose()) {
+					this.results.realClose(false);
+				}
 			}
-		}
-
-		CachedResultSetMetaData cachedMetaData = null;
-
-		// If there isn't a limit clause in the SQL
-		// then limit the number of rows to return in
-		// an efficient manner. Only do this if
-		// setMaxRows() hasn't been used on any Statements
-		// generated from the current Connection (saves
-		// a query, and network traffic).
-		synchronized (this.connection.getMutex()) {
+	
+			CachedResultSetMetaData cachedMetaData = null;
+	
+			// If there isn't a limit clause in the SQL
+			// then limit the number of rows to return in
+			// an efficient manner. Only do this if
+			// setMaxRows() hasn't been used on any Statements
+			// generated from the current Connection (saves
+			// a query, and network traffic).
+			
 			if (useServerFetch()) {
 				this.results = createResultSetUsingServerFetch(sql);
 
@@ -1197,31 +1199,13 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized int executeUpdate(String sql) throws SQLException {
+	public int executeUpdate(String sql) throws SQLException {
 		return executeUpdate(sql, false);
 	}
 
-	protected synchronized int executeUpdate(String sql, boolean isBatch)
+	protected int executeUpdate(String sql, boolean isBatch)
 			throws SQLException {
-		this.wasCancelled = false;
 
-		checkNullOrEmptyQuery(sql);
-
-		checkClosed();
-
-		if (this.connection.isReadOnly()) {
-			throw SQLError.createSQLException(Messages
-					.getString("Statement.42") //$NON-NLS-1$
-					+ Messages.getString("Statement.43"), //$NON-NLS-1$
-					SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
-		}
-
-		if (StringUtils.startsWithIgnoreCaseAndWs(sql, "select")) { //$NON-NLS-1$
-			throw SQLError.createSQLException(Messages
-					.getString("Statement.46"), //$NON-NLS-1$
-					"01S03"); //$NON-NLS-1$
-		}
-
 		char firstStatementChar = StringUtils.firstNonWsCharUc(sql);
 
 		if (this.doEscapeProcessing) {
@@ -1235,18 +1219,38 @@
 			}
 		}
 
-		if (this.results != null) {
-			if (!this.connection.getHoldResultsOpenOverStatementClose()) {
-				this.results.realClose(false);
-			}
-		}
-
-		// The checking and changing of catalogs
-		// must happen in sequence, so synchronize
-		// on the same mutex that _conn is using
 		ResultSet rs = null;
 
 		synchronized (this.connection.getMutex()) {
+			this.wasCancelled = false;
+	
+			checkNullOrEmptyQuery(sql);
+	
+			checkClosed();
+	
+			if (this.connection.isReadOnly()) {
+				throw SQLError.createSQLException(Messages
+						.getString("Statement.42") //$NON-NLS-1$
+						+ Messages.getString("Statement.43"), //$NON-NLS-1$
+						SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
+			}
+	
+			if (StringUtils.startsWithIgnoreCaseAndWs(sql, "select")) { //$NON-NLS-1$
+				throw SQLError.createSQLException(Messages
+						.getString("Statement.46"), //$NON-NLS-1$
+						"01S03"); //$NON-NLS-1$
+			}
+	
+			if (this.results != null) {
+				if (!this.connection.getHoldResultsOpenOverStatementClose()) {
+					this.results.realClose(false);
+				}
+			}
+	
+			// The checking and changing of catalogs
+			// must happen in sequence, so synchronize
+			// on the same mutex that _conn is using
+		
 			CancelThread timeoutThread = null;
 
 			try {
@@ -1429,7 +1433,7 @@
 	 * Optimization to only use one calendar per-session, or calculate it for
 	 * each call, depending on user configuration
 	 */
-	protected synchronized Calendar getCalendarInstanceForSessionOrNew() {
+	protected Calendar getCalendarInstanceForSessionOrNew() {
 		if (this.connection != null) {
 			return this.connection.getCalendarInstanceForSessionOrNew();
 		} else {
@@ -1446,7 +1450,7 @@
 	 * @throws SQLException
 	 *             if an error occurs
 	 */
-	public synchronized java.sql.Connection getConnection() throws SQLException {
+	public java.sql.Connection getConnection() throws SQLException {
 		return this.connection;
 	}
 
@@ -1470,7 +1474,7 @@
 	 * @throws SQLException
 	 *             if an error occurs
 	 */
-	public synchronized int getFetchSize() throws SQLException {
+	public int getFetchSize() throws SQLException {
 		return this.fetchSize;
 	}
 
@@ -1482,7 +1486,7 @@
 	 * @throws SQLException
 	 *             DOCUMENT ME!
 	 */
-	public synchronized java.sql.ResultSet getGeneratedKeys()
+	public java.sql.ResultSet getGeneratedKeys()
 			throws SQLException {
 		if (this.batchedGeneratedKeys == null) {
 			return getGeneratedKeysInternal();
@@ -1502,7 +1506,7 @@
 	 * implementation from ServerPreparedStatement when dealing with batched
 	 * updates.
 	 */
-	protected synchronized java.sql.ResultSet getGeneratedKeysInternal()
+	protected java.sql.ResultSet getGeneratedKeysInternal()
 			throws SQLException {
 		Field[] fields = new Field[1];
 		fields[0] = new Field("", "GENERATED_KEY", Types.BIGINT, 17); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1560,7 +1564,7 @@
 	 * 
 	 * @return the last update ID.
 	 */
-	public synchronized long getLastInsertID() {
+	public long getLastInsertID() {
 		return this.lastInsertId;
 	}
 
@@ -1576,7 +1580,7 @@
 	 * 
 	 * @return the current update count.
 	 */
-	public synchronized long getLongUpdateCount() {
+	public long getLongUpdateCount() {
 		if (this.results == null) {
 			return -1;
 		}
@@ -1599,7 +1603,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized int getMaxFieldSize() throws SQLException {
+	public int getMaxFieldSize() throws SQLException {
 		return this.maxFieldSize;
 	}
 
@@ -1613,7 +1617,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized int getMaxRows() throws SQLException {
+	public int getMaxRows() throws SQLException {
 		if (this.maxRows <= 0) {
 			return 0;
 		}
@@ -1637,7 +1641,7 @@
 	/**
 	 * @see Statement#getMoreResults(int)
 	 */
-	public synchronized boolean getMoreResults(int current) throws SQLException {
+	public boolean getMoreResults(int current) throws SQLException {
 
 		if (this.results == null) {
 			return false;
@@ -1790,7 +1794,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs (why?)
 	 */
-	public synchronized java.sql.ResultSet getResultSet() throws SQLException {
+	public java.sql.ResultSet getResultSet() throws SQLException {
 		return ((this.results != null) && this.results.reallyResult()) ? (java.sql.ResultSet) this.results
 				: null;
 	}
@@ -1803,7 +1807,7 @@
 	 * @throws SQLException
 	 *             if an error occurs
 	 */
-	public synchronized int getResultSetConcurrency() throws SQLException {
+	public int getResultSetConcurrency() throws SQLException {
 		return this.resultSetConcurrency;
 	}
 
@@ -1814,7 +1818,7 @@
 		return java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT;
 	}
 
-	protected synchronized ResultSet getResultSetInternal() {
+	protected ResultSet getResultSetInternal() {
 		return this.results;
 	}
 
@@ -1826,7 +1830,7 @@
 	 * @throws SQLException
 	 *             if an error occurs.
 	 */
-	public synchronized int getResultSetType() throws SQLException {
+	public int getResultSetType() throws SQLException {
 		return this.resultSetType;
 	}
 
@@ -1840,7 +1844,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized int getUpdateCount() throws SQLException {
+	public int getUpdateCount() throws SQLException {
 		if (this.results == null) {
 			return -1;
 		}
@@ -1881,7 +1885,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized java.sql.SQLWarning getWarnings() throws SQLException {
+	public java.sql.SQLWarning getWarnings() throws SQLException {
 		checkClosed();
 
 		if (this.connection != null && !this.connection.isClosed()
@@ -2046,7 +2050,7 @@
 	 * @exception SQLException
 	 *                if a database access error occurs
 	 */
-	public synchronized void setEscapeProcessing(boolean enable)
+	public void setEscapeProcessing(boolean enable)
 			throws SQLException {
 		this.doEscapeProcessing = enable;
 	}
@@ -2092,7 +2096,7 @@
 	 *                if a database-access error occurs, or the condition 0
 	 *                &lt;= rows &lt;= this.getMaxRows() is not satisfied.
 	 */
-	public synchronized void setFetchSize(int rows) throws SQLException {
+	public void setFetchSize(int rows) throws SQLException {
 		if (((rows < 0) && (rows != Integer.MIN_VALUE))
 				|| ((this.maxRows != 0) && (this.maxRows != -1) && (rows > this
 						.getMaxRows()))) {
@@ -2117,7 +2121,7 @@
 	 * @exception SQLException
 	 *                if size exceeds buffer size
 	 */
-	public synchronized void setMaxFieldSize(int max) throws SQLException {
+	public void setMaxFieldSize(int max) throws SQLException {
 		if (max < 0) {
 			throw SQLError.createSQLException(Messages
 					.getString("Statement.11"), //$NON-NLS-1$
@@ -2148,7 +2152,7 @@
 	 * 
 	 * @see getMaxRows
 	 */
-	public synchronized void setMaxRows(int max) throws SQLException {
+	public void setMaxRows(int max) throws SQLException {
 		if ((max > MysqlDefs.MAX_ROWS) || (max < 0)) {
 			throw SQLError
 					.createSQLException(
@@ -2202,7 +2206,7 @@
 	 * @param concurrencyFlag
 	 *            DOCUMENT ME!
 	 */
-	synchronized void setResultSetConcurrency(int concurrencyFlag) {
+	void setResultSetConcurrency(int concurrencyFlag) {
 		this.resultSetConcurrency = concurrencyFlag;
 	}
 
@@ -2212,7 +2216,7 @@
 	 * @param typeFlag
 	 *            DOCUMENT ME!
 	 */
-	synchronized void setResultSetType(int typeFlag) {
+	void setResultSetType(int typeFlag) {
 		this.resultSetType = typeFlag;
 	}
 

Thread
Connector/J commit: r5133 - branches/branch_5_0/connector-j/src/com/mysql/jdbcmmatthews4 Apr