Skip to content

Commit

Permalink
Fix for Bug#26440544, CONNECTOR/J SHOULD NOT USE
Browse files Browse the repository at this point in the history
TX_{READ_ONLY,ISOLATION} WHICH IS PLANNED FOR REMOVAL.
  • Loading branch information
soklakov committed Jul 20, 2017
1 parent a7fdc41 commit cfc7870
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Version 5.1.44

- Fix for Bug#26440544, CONNECTOR/J SHOULD NOT USE TX_{READ_ONLY,ISOLATION} WHICH IS PLANNED FOR REMOVAL.

Version 5.1.43

Expand Down
24 changes: 11 additions & 13 deletions src/com/mysql/jdbc/ConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1280,14 +1280,7 @@ private void checkServerEncoding() throws SQLException {
* @throws SQLException
*/
private void checkTransactionIsolationLevel() throws SQLException {
String txIsolationName = null;

if (versionMeetsMinimum(4, 0, 3)) {
txIsolationName = "tx_isolation";
} else {
txIsolationName = "transaction_isolation";
}

String txIsolationName = versionMeetsMinimum(4, 0, 3) && !versionMeetsMinimum(8, 0, 3) ? "tx_isolation" : "transaction_isolation";
String s = this.serverVariables.get(txIsolationName);

if (s != null) {
Expand Down Expand Up @@ -3001,11 +2994,12 @@ public int getTransactionIsolation() throws SQLException {

String query = null;

int offset = 0;
int offset = 1;

if (versionMeetsMinimum(4, 0, 3)) {
if (versionMeetsMinimum(8, 0, 3)) {
query = "SELECT @@session.transaction_isolation";
} else if (versionMeetsMinimum(4, 0, 3)) {
query = "SELECT @@session.tx_isolation";
offset = 1;
} else {
query = "SHOW VARIABLES LIKE 'transaction_isolation'";
offset = 2;
Expand Down Expand Up @@ -3548,7 +3542,7 @@ public boolean isReadOnly(boolean useSessionStatus) throws SQLException {
try {
stmt = getMetadataSafeStatement();

rs = stmt.executeQuery("select @@session.tx_read_only");
rs = stmt.executeQuery(versionMeetsMinimum(8, 0, 3) ? "select @@session.transaction_read_only" : "select @@session.tx_read_only");
if (rs.next()) {
return rs.getInt(1) != 0; // mysql has a habit of tri+ state booleans
}
Expand Down Expand Up @@ -3786,7 +3780,11 @@ private void loadServerVariables() throws SQLException {
queryBuf.append(", @@sql_mode AS sql_mode");
queryBuf.append(", @@system_time_zone AS system_time_zone");
queryBuf.append(", @@time_zone AS time_zone");
queryBuf.append(", @@tx_isolation AS tx_isolation");
if (versionMeetsMinimum(8, 0, 3)) {
queryBuf.append(", @@transaction_isolation AS transaction_isolation");
} else {
queryBuf.append(", @@tx_isolation AS tx_isolation");
}
queryBuf.append(", @@wait_timeout AS wait_timeout");

results = stmt.executeQuery(queryBuf.toString());
Expand Down
10 changes: 8 additions & 2 deletions src/testsuite/regression/ConnectionRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,9 @@ public void testBug27655() throws Exception {
loggedConn = getConnectionWithProps(props);
loggedConn.getTransactionIsolation();

if (versionMeetsMinimum(4, 0, 3)) {
if (versionMeetsMinimum(8, 0, 3)) {
assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'transaction_isolation'"));
} else if (versionMeetsMinimum(4, 0, 3)) {
assertEquals(-1, StandardLogger.getBuffer().toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'"));
}
} finally {
Expand Down Expand Up @@ -7555,7 +7557,11 @@ public void testBug75592() throws Exception {

assertEquals(serverVariables.get("system_time_zone"), con.getServerVariable("system_time_zone"));
assertEquals(serverVariables.get("time_zone"), con.getServerVariable("time_zone"));
assertEquals(serverVariables.get("tx_isolation"), con.getServerVariable("tx_isolation"));
if (con.versionMeetsMinimum(8, 0, 3)) {
assertEquals(serverVariables.get("transaction_isolation"), con.getServerVariable("transaction_isolation"));
} else {
assertEquals(serverVariables.get("tx_isolation"), con.getServerVariable("tx_isolation"));
}
assertEquals(serverVariables.get("wait_timeout"), con.getServerVariable("wait_timeout"));
if (!versionMeetsMinimum(5, 5, 0)) {
assertEquals(serverVariables.get("language"), con.getServerVariable("language"));
Expand Down
9 changes: 6 additions & 3 deletions src/testsuite/simple/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,9 @@ public void testUseLocalSessionState() throws Exception {
conn1.getTransactionIsolation();

String logAsString = StandardLogger.getBuffer().toString();
String txIsolationName = versionMeetsMinimum(4, 0, 3) && !versionMeetsMinimum(8, 0, 3) ? "tx_isolation" : "transaction_isolation";

assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE 'tx_isolation'") == -1
assertTrue(logAsString.indexOf("SET SESSION") == -1 && logAsString.indexOf("SHOW VARIABLES LIKE '" + txIsolationName + "'") == -1
&& logAsString.indexOf("SET autocommit=") == -1);
}

Expand Down Expand Up @@ -1715,6 +1716,8 @@ public void testReadOnly56() throws Exception {

Connection localState = getConnectionWithProps("profileSql=true,useLocalSessionState=true");

String txReadOnlyName = versionMeetsMinimum(8, 0, 3) ? "transaction_read_only" : "tx_read_only";

for (int i = 0; i < 2; i++) {
StandardLogger.startLoggingToBuffer();
localState.setReadOnly(true);
Expand All @@ -1725,7 +1728,7 @@ public void testReadOnly56() throws Exception {
}
StandardLogger.startLoggingToBuffer();
localState.isReadOnly();
assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1);
assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1);
}

Connection noOptimization = getConnectionWithProps("profileSql=true,readOnlyPropagatesToServer=false");
Expand All @@ -1736,7 +1739,7 @@ public void testReadOnly56() throws Exception {
assertTrue(StandardLogger.getBuffer().toString().indexOf("set session transaction read only") == -1);
StandardLogger.startLoggingToBuffer();
noOptimization.isReadOnly();
assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session.tx_read_only") == -1);
assertTrue(StandardLogger.getBuffer().toString().indexOf("select @@session." + txReadOnlyName) == -1);
}
} finally {
StandardLogger.dropBuffer();
Expand Down

0 comments on commit cfc7870

Please sign in to comment.