From 9cf39061f9023e236fc1f1801a739fbc1440aa77 Mon Sep 17 00:00:00 2001 From: rusher Date: Tue, 5 Sep 2017 14:47:59 +0200 Subject: [PATCH] [misc] remove unused access of @@sql_mode during connection time --- .../protocol/AbstractConnectProtocol.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java index ddd64a212..62cd72749 100644 --- a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java +++ b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java @@ -115,7 +115,6 @@ public abstract class AbstractConnectProtocol implements Protocol { private static final byte[] SESSION_QUERY = ("SELECT @@max_allowed_packet," + "@@system_time_zone," + "@@time_zone," - + "@@sql_mode," + "@@auto_increment_increment").getBytes(StandardCharsets.UTF_8); private static final byte[] IS_MASTER_QUERY = "show global variables like 'innodb_read_only'".getBytes(StandardCharsets.UTF_8); private static final Logger logger = LoggerFactory.getLogger(AbstractConnectProtocol.class); @@ -148,7 +147,6 @@ public abstract class AbstractConnectProtocol implements Protocol { private int majorVersion; private int minorVersion; private int patchVersion; - private Map serverData; private TimeZone timeZone; private final LruTraceCache traceCache = new LruTraceCache(); @@ -405,7 +403,6 @@ private void connect(String host, int port) throws SQLException, IOException { handleConnectionPhases(host); connected = true; - serverData = new TreeMap<>(); if (options.useCompression) { writer = new CompressPacketOutputStream(writer.getOutputStream(), options.maxQuerySizeToLog); @@ -416,16 +413,17 @@ private void connect(String host, int port) throws SQLException, IOException { } } + Map serverData = new TreeMap<>(); if (options.usePipelineAuth && !options.createDatabaseIfNotExist) { try { sendPipelineAdditionalData(); - readPipelineAdditionalData(); + readPipelineAdditionalData(serverData); } catch (SQLException sqle) { //in case pipeline is not supported //(proxy flush socket after reading first packet) - additionalData(); + additionalData(serverData); } - } else additionalData(); + } else additionalData(serverData); // Extract socketTimeout URL parameter if (options.socketTimeout != null) socket.setSoTimeout(options.socketTimeout); @@ -433,12 +431,11 @@ private void connect(String host, int port) throws SQLException, IOException { writer.setMaxAllowedPacket(Integer.parseInt(serverData.get("max_allowed_packet"))); autoIncrementIncrement = Integer.parseInt(serverData.get("auto_increment_increment")); - loadCalendar(); + loadCalendar(serverData); reader.setServerThreadId(this.serverThreadId, isMasterConnection()); writer.setServerThreadId(this.serverThreadId, isMasterConnection()); - serverData = null; activeStreamingResult = null; hostFailed = false; } catch (IOException | SQLException ioException) { @@ -495,7 +492,7 @@ private void sendRequestSessionVariables() throws IOException { writer.flush(); } - private void readRequestSessionVariables() throws SQLException { + private void readRequestSessionVariables(Map serverData) throws SQLException { Results results = new Results(); getResult(results); @@ -507,8 +504,7 @@ private void readRequestSessionVariables() throws SQLException { serverData.put("max_allowed_packet", resultSet.getString(1)); serverData.put("system_time_zone", resultSet.getString(2)); serverData.put("time_zone", resultSet.getString(3)); - serverData.put("sql_mode", resultSet.getString(4)); - serverData.put("auto_increment_increment", resultSet.getString(5)); + serverData.put("auto_increment_increment", resultSet.getString(4)); } else { throw new SQLException("Error reading SessionVariables results. Socket is connected ? " @@ -530,7 +526,7 @@ private void sendUseDatabaseIfNotExist(String quotedDb) throws IOException { writer.flush(); } - private void readPipelineAdditionalData() throws SQLException { + private void readPipelineAdditionalData(Map serverData) throws SQLException { SQLException resultingException = null; //read set session OKPacket @@ -543,7 +539,7 @@ private void readPipelineAdditionalData() throws SQLException { boolean canTrySessionWithShow = false; try { - readRequestSessionVariables(); + readRequestSessionVariables(serverData); } catch (SQLException sqlException) { if (resultingException == null) { resultingException = new SQLException("could not load system variables", @@ -564,7 +560,7 @@ private void readPipelineAdditionalData() throws SQLException { if (canTrySessionWithShow) { //fallback in case of galera non primary nodes that permit only show / set command, //not SELECT when not part of quorum - requestSessionDataWithShow(); + requestSessionDataWithShow(serverData); } if (resultingException != null) throw resultingException; @@ -572,14 +568,13 @@ private void readPipelineAdditionalData() throws SQLException { } - private void requestSessionDataWithShow() throws SQLException { + private void requestSessionDataWithShow(Map serverData) throws SQLException { try { Results results = new Results(); executeQuery(true, results, "SHOW VARIABLES WHERE Variable_name in (" + "'max_allowed_packet'," + "'system_time_zone'," + "'time_zone'," - + "'sql_mode'," + "'auto_increment_increment')"); results.commandEnd(); ResultSet resultSet = results.getResultSet(); @@ -597,16 +592,16 @@ private void requestSessionDataWithShow() throws SQLException { } } - private void additionalData() throws IOException, SQLException { + private void additionalData(Map serverData) throws IOException, SQLException { sendSessionInfos(); getResult(new Results()); try { sendRequestSessionVariables(); - readRequestSessionVariables(); + readRequestSessionVariables(serverData); } catch (SQLException sqlException) { - requestSessionDataWithShow(); + requestSessionDataWithShow(serverData); } //for aurora, check that connection is master @@ -842,7 +837,7 @@ private long initializeClientCapabilities(long serverCapabilities) { return capabilities; } - private void loadCalendar() throws SQLException { + private void loadCalendar(Map serverData) throws SQLException { if (options.useLegacyDatetimeCode) { //legacy use client timezone timeZone = Calendar.getInstance().getTimeZone(); @@ -884,10 +879,6 @@ private void loadCalendar() throws SQLException { } - public String getServerData(String code) { - return serverData.get(code); - } - /** * Check that current connection is a master connection (not read-only) *