[Commits] Rev 402: Speed up Connection.getWarnings() - avoid unnicessary "show warnings", if last statement did not produce any warnings. in file:///H:/bzr/mariadb-jdbc-push/

Vladislav Vaintroub wlad at montyprogram.com
Fri Feb 8 00:13:07 EET 2013


At file:///H:/bzr/mariadb-jdbc-push/

------------------------------------------------------------
revno: 402
revision-id: wlad at montyprogram.com-20130207221302-mwom6nogl01rqgs9
parent: wlad at montyprogram.com-20130203203959-deg198021t1ovavj
committer: Vladislav Vaintroub <wlad at montyprogram.com>
branch nick: mariadb-jdbc-push
timestamp: Thu 2013-02-07 23:13:02 +0100
message:
  Speed up Connection.getWarnings() - avoid unnicessary "show warnings", if last statement did not produce any warnings.
-------------- next part --------------
=== modified file 'src/main/java/org/mariadb/jdbc/MySQLConnection.java'
--- a/src/main/java/org/mariadb/jdbc/MySQLConnection.java	2013-02-02 12:35:04 +0000
+++ b/src/main/java/org/mariadb/jdbc/MySQLConnection.java	2013-02-07 22:13:02 +0000
@@ -450,7 +450,7 @@ public final class MySQLConnection
      * @see java.sql.SQLWarning
      */
     public SQLWarning getWarnings() throws SQLException {
-        if (warningsCleared || isClosed()) {
+        if (warningsCleared || isClosed() || !protocol.hasWarnings) {
             return null;
         }
         Statement st = null;

=== modified file 'src/main/java/org/mariadb/jdbc/internal/common/queryresults/StreamingSelectResult.java'
--- a/src/main/java/org/mariadb/jdbc/internal/common/queryresults/StreamingSelectResult.java	2012-12-15 23:39:35 +0000
+++ b/src/main/java/org/mariadb/jdbc/internal/common/queryresults/StreamingSelectResult.java	2013-02-07 22:13:02 +0000
@@ -101,6 +101,7 @@ public class StreamingSelectResult exten
                 protocol.activeResult = null;
                 protocol.moreResults = eofPacket.getStatusFlags().contains(EOFPacket.ServerStatus.SERVER_MORE_RESULTS_EXISTS);
                 warningCount = eofPacket.getWarningCount();
+                protocol.hasWarnings = (warningCount > 0);
                 isEOF = true;
                 values = null;
                 return false;

=== modified file 'src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java'
--- a/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java	2013-01-13 23:15:13 +0000
+++ b/src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java	2013-02-07 22:13:02 +0000
@@ -111,6 +111,7 @@ public class MySQLProtocol implements Pr
     private final Properties info;
     private  long serverThreadId;
     public boolean moreResults = false;
+    public boolean hasWarnings = false;
     public StreamingSelectResult activeResult= null;
     public int datatypeMappingFlags;
     public Set<ServerStatus> serverStatus;
@@ -416,6 +417,7 @@ public class MySQLProtocol implements Pr
 
            activeResult = null;
            moreResults = false;
+           hasWarnings = false;
            connected = true;
            hostFailed = false; // Prevent reconnects
        } catch (IOException e) {
@@ -726,6 +728,7 @@ public class MySQLProtocol implements Pr
         switch (resultPacket.getResultType()) {
             case ERROR:
                 this.moreResults = false;
+                this.hasWarnings = false;
                 ErrorPacket ep = (ErrorPacket) resultPacket;
                 if (dQuery != null) {
                     log.warning("Could not execute query " + dQuery + ": " + ((ErrorPacket) resultPacket).getMessage());
@@ -738,6 +741,7 @@ public class MySQLProtocol implements Pr
                 final OKPacket okpacket = (OKPacket) resultPacket;
                 serverStatus = okpacket.getServerStatus();
                 this.moreResults = serverStatus.contains(ServerStatus.MORE_RESULTS_EXISTS);
+                this.hasWarnings = (okpacket.getWarnings() > 0);
                 final QueryResult updateResult = new UpdateResult(okpacket.getAffectedRows(),
                         okpacket.getWarnings(),
                         okpacket.getMessage(),
@@ -745,6 +749,7 @@ public class MySQLProtocol implements Pr
                 log.fine("OK, " + okpacket.getAffectedRows());
                 return updateResult;
             case RESULTSET:
+                this.hasWarnings = false;
                 log.fine("SELECT executed, fetching result set");
                 ResultSetPacket resultSetPacket = (ResultSetPacket)resultPacket;
                 try {



More information about the commits mailing list