Modified:
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
branches/branch_5_0/connector-j/src/testsuite/simple/ConnectionTest.java
branches/branch_5_1/connector-j/CHANGES
branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java
Log:
- When "useLocalSessionState" is set to "true" and connected to a MySQL-5.0 or
later server, the JDBC driver will now determine whether an actual "commit" or
"rollback" statement needs to be sent to the database when Connection.commit()
or Connection.rollback() is called.
This is especially helpful for high-load situations with connection pools that
always call Connection.rollback() on connection check-in/check-out because it
avoids a round-trip to the server.
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_0/connector-j/CHANGES 2007-05-04 18:41:42 UTC (rev 6417)
@@ -158,7 +158,16 @@
* "bestResponseTime" - the driver will route the request to the host that had
the best response time for the previous transaction.
+
+ - When "useLocalSessionState" is set to "true" and connected to a MySQL-5.0 or
+ later server, the JDBC driver will now determine whether an actual "commit" or
+ "rollback" statement needs to be sent to the database when Connection.commit()
+ or Connection.rollback() is called.
+ This is especially helpful for high-load situations with connection pools that
+ always call Connection.rollback() on connection check-in/check-out because it
+ avoids a round-trip to the server.
+
03-01-07 - Version 5.0.5
- Fixed BUG#23645 - Some collations/character sets reported as "unknown"
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 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/Connection.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -2273,6 +2273,12 @@
if (this.autoCommit && !getRelaxAutoCommit()) {
throw SQLError.createSQLException("Can't call commit when autocommit=true");
} else if (this.transactionsSupported) {
+ if (getUseLocalSessionState() && versionMeetsMinimum(5, 0, 0)) {
+ if (!this.io.inTransactionOnServer()) {
+ return; // effectively a no-op
+ }
+ }
+
execSQL(null, "commit", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY, false,
@@ -5295,6 +5301,12 @@
}
private void rollbackNoChecks() throws SQLException {
+ if (getUseLocalSessionState() && versionMeetsMinimum(5, 0, 0)) {
+ if (!this.io.inTransactionOnServer()) {
+ return; // effectively a no-op
+ }
+ }
+
execSQL(null, "rollback", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY, false,
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -24,6 +24,7 @@
*/
package com.mysql.jdbc;
+import com.mysql.jdbc.ConnectionPropertiesImpl.BooleanConnectionProperty;
import com.mysql.jdbc.log.Jdk14Logger;
import com.mysql.jdbc.log.Log;
import com.mysql.jdbc.log.StandardLogger;
@@ -1385,11 +1386,14 @@
"option is exclusive of the \"useTimezone=true\" configuration option.)",
"5.0.0",
MISC_CATEGORY, Integer.MIN_VALUE);
+
private BooleanConnectionProperty useLocalSessionState = new BooleanConnectionProperty(
"useLocalSessionState",
false,
"Should the driver refer to the internal values of autocommit and transaction isolation that are set "
- + " by Connection.setAutoCommit() and Connection.setTransactionIsolation(), rather than querying the database?",
+ + "by Connection.setAutoCommit() and Connection.setTransactionIsolation() and transaction state "
+ + "as maintained by the protocol, rather than querying the database or blindly "
+ + "sending commands to the database for commit() or rollback() method calls?",
"3.1.7", PERFORMANCE_CATEGORY, Integer.MIN_VALUE);
private BooleanConnectionProperty useOldAliasMetadataBehavior = new BooleanConnectionProperty(
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/MysqlIO.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -778,7 +778,7 @@
boolean autoCommitModeOnServer = ((this.serverStatus &
SERVER_STATUS_AUTOCOMMIT) != 0);
- if (!autoCommitFlag) {
+ if (!autoCommitFlag && versionMeetsMinimum(5, 0, 0)) {
// Just to be safe, check if a transaction is in progress on the server....
// if so, then we must be in autoCommit == false
// therefore return the opposite of transaction status
@@ -793,6 +793,10 @@
return true;
}
+
+ protected boolean inTransactionOnServer() {
+ return (this.serverStatus & SERVER_STATUS_IN_TRANS) != 0;
+ }
/**
* Re-authenticates as the given user and password
@@ -3925,7 +3929,7 @@
}
protected int getServerStatus() {
- return serverStatus;
+ return this.serverStatus;
}
protected List fetchRowsViaCursor(List fetchedRows, long statementId,
Modified: branches/branch_5_0/connector-j/src/testsuite/simple/ConnectionTest.java
===================================================================
--- branches/branch_5_0/connector-j/src/testsuite/simple/ConnectionTest.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_0/connector-j/src/testsuite/simple/ConnectionTest.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -1384,4 +1384,77 @@
}
}
}
+
+ public void testUseLocalSessionStateRollback() throws Exception {
+ if (!versionMeetsMinimum(5, 0, 0)) {
+ return;
+ }
+
+ Properties props = new Properties();
+ props.setProperty("useLocalSessionState", "true");
+ props.setProperty("profileSQL", "true");
+
+ StringBuffer buf = new StringBuffer();
+ StandardLogger.bufferedLog = buf;
+
+ createTable("testUseLocalSessionState", "(field1 varchar(32)) ENGINE=InnoDB");
+
+ Connection localStateConn = null;
+ Statement localStateStmt = null;
+
+ try {
+ localStateConn = getConnectionWithProps(props);
+ localStateStmt = localStateConn.createStatement();
+
+ localStateConn.setAutoCommit(false);
+ localStateStmt.executeUpdate("INSERT INTO testUseLocalSessionState VALUES ('abc')");
+ localStateConn.rollback();
+ localStateConn.rollback();
+ localStateStmt.executeUpdate("INSERT INTO testUseLocalSessionState VALUES ('abc')");
+ localStateConn.commit();
+ localStateConn.commit();
+ localStateStmt.close();
+ } finally {
+ StandardLogger.bufferedLog = null;
+
+ if (localStateStmt != null) {
+ localStateStmt.close();
+ }
+
+ if (localStateConn != null) {
+ localStateConn.close();
+ }
+ }
+
+ int rollbackCount = 0;
+ int rollbackPos = 0;
+
+ String searchIn = buf.toString();
+
+ while (rollbackPos != -1) {
+ rollbackPos = searchIn.indexOf("rollback", rollbackPos);
+
+ if (rollbackPos != -1) {
+ rollbackPos += "rollback".length();
+ rollbackCount++;
+ }
+ }
+
+ assertEquals(1, rollbackCount);
+
+ int commitCount = 0;
+ int commitPos = 0;
+
+ // space is important here, we don't want to count "autocommit"
+ while (commitPos != -1) {
+ commitPos = searchIn.indexOf(" commit", commitPos);
+
+ if (commitPos != -1) {
+ commitPos += " commit".length();
+ commitCount++;
+ }
+ }
+
+ assertEquals(1, commitCount);
+ }
}
Modified: branches/branch_5_1/connector-j/CHANGES
===================================================================
--- branches/branch_5_1/connector-j/CHANGES 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_1/connector-j/CHANGES 2007-05-04 18:41:42 UTC (rev 6417)
@@ -237,7 +237,16 @@
* "bestResponseTime" - the driver will route the request to the host that had
the best response time for the previous transaction.
-
+
+ - When "useLocalSessionState" is set to "true" and connected to a MySQL-5.0 or
+ later server, the JDBC driver will now determine whether an actual "commit" or
+ "rollback" statement needs to be sent to the database when Connection.commit()
+ or Connection.rollback() is called.
+
+ This is especially helpful for high-load situations with connection pools that
+ always call Connection.rollback() on connection check-in/check-out because it
+ avoids a round-trip to the server.
+
03-01-07 - Version 5.0.5
- Fixed BUG#23645 - Some collations/character sets reported as "unknown"
Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionImpl.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -1508,6 +1508,12 @@
if (this.autoCommit && !getRelaxAutoCommit()) {
throw SQLError.createSQLException("Can't call commit when autocommit=true");
} else if (this.transactionsSupported) {
+ if (getUseLocalSessionState() && versionMeetsMinimum(5, 0, 0)) {
+ if (!this.io.inTransactionOnServer()) {
+ return; // effectively a no-op
+ }
+ }
+
execSQL(null, "commit", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY, false,
@@ -4491,6 +4497,12 @@
}
private void rollbackNoChecks() throws SQLException {
+ if (getUseLocalSessionState() && versionMeetsMinimum(5, 0, 0)) {
+ if (!this.io.inTransactionOnServer()) {
+ return; // effectively a no-op
+ }
+ }
+
execSQL(null, "rollback", -1, null,
java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY, false,
Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ConnectionPropertiesImpl.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -1401,11 +1401,14 @@
"option is exclusive of the \"useTimezone=true\" configuration option.)",
"5.0.0",
MISC_CATEGORY, Integer.MIN_VALUE);
+
private BooleanConnectionProperty useLocalSessionState = new BooleanConnectionProperty(
"useLocalSessionState",
false,
"Should the driver refer to the internal values of autocommit and transaction isolation that are set "
- + " by Connection.setAutoCommit() and Connection.setTransactionIsolation(), rather than querying the database?",
+ + "by Connection.setAutoCommit() and Connection.setTransactionIsolation() and transaction state "
+ + "as maintained by the protocol, rather than querying the database or blindly "
+ + "sending commands to the database for commit() or rollback() method calls?",
"3.1.7", PERFORMANCE_CATEGORY, Integer.MIN_VALUE);
private BooleanConnectionProperty useOldAliasMetadataBehavior = new BooleanConnectionProperty(
Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/MysqlIO.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -767,7 +767,7 @@
boolean autoCommitModeOnServer = ((this.serverStatus &
SERVER_STATUS_AUTOCOMMIT) != 0);
- if (!autoCommitFlag) {
+ if (!autoCommitFlag && versionMeetsMinimum(5, 0, 0)) {
// Just to be safe, check if a transaction is in progress on the server....
// if so, then we must be in autoCommit == false
// therefore return the opposite of transaction status
@@ -782,6 +782,10 @@
return true;
}
+
+ protected boolean inTransactionOnServer() {
+ return (this.serverStatus & SERVER_STATUS_IN_TRANS) != 0;
+ }
/**
* Re-authenticates as the given user and password
@@ -3933,7 +3937,7 @@
}
protected int getServerStatus() {
- return serverStatus;
+ return this.serverStatus;
}
protected List fetchRowsViaCursor(List fetchedRows, long statementId,
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java 2007-05-04 17:38:32 UTC (rev 6416)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/ConnectionTest.java 2007-05-04 18:41:42 UTC (rev 6417)
@@ -1384,4 +1384,77 @@
}
}
}
+
+ public void testUseLocalSessionStateRollback() throws Exception {
+ if (!versionMeetsMinimum(5, 0, 0)) {
+ return;
+ }
+
+ Properties props = new Properties();
+ props.setProperty("useLocalSessionState", "true");
+ props.setProperty("profileSQL", "true");
+
+ StringBuffer buf = new StringBuffer();
+ StandardLogger.bufferedLog = buf;
+
+ createTable("testUseLocalSessionState", "(field1 varchar(32)) ENGINE=InnoDB");
+
+ Connection localStateConn = null;
+ Statement localStateStmt = null;
+
+ try {
+ localStateConn = getConnectionWithProps(props);
+ localStateStmt = localStateConn.createStatement();
+
+ localStateConn.setAutoCommit(false);
+ localStateStmt.executeUpdate("INSERT INTO testUseLocalSessionState VALUES ('abc')");
+ localStateConn.rollback();
+ localStateConn.rollback();
+ localStateStmt.executeUpdate("INSERT INTO testUseLocalSessionState VALUES ('abc')");
+ localStateConn.commit();
+ localStateConn.commit();
+ localStateStmt.close();
+ } finally {
+ StandardLogger.bufferedLog = null;
+
+ if (localStateStmt != null) {
+ localStateStmt.close();
+ }
+
+ if (localStateConn != null) {
+ localStateConn.close();
+ }
+ }
+
+ int rollbackCount = 0;
+ int rollbackPos = 0;
+
+ String searchIn = buf.toString();
+
+ while (rollbackPos != -1) {
+ rollbackPos = searchIn.indexOf("rollback", rollbackPos);
+
+ if (rollbackPos != -1) {
+ rollbackPos += "rollback".length();
+ rollbackCount++;
+ }
+ }
+
+ assertEquals(1, rollbackCount);
+
+ int commitCount = 0;
+ int commitPos = 0;
+
+ // space is important here, we don't want to count "autocommit"
+ while (commitPos != -1) {
+ commitPos = searchIn.indexOf(" commit", commitPos);
+
+ if (commitPos != -1) {
+ commitPos += " commit".length();
+ commitCount++;
+ }
+ }
+
+ assertEquals(1, commitCount);
+ }
}
| Thread |
|---|
| • Connector/J commit: r6417 - in branches: branch_5_0/connector-j branch_5_0/connector-j/src/com/mysql/jdbc branch_5_0/connector-j/src/testsuite/simple ... | mmatthews | 4 May |