]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5394 open SQL write connection only on first statement
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 14:31:13 +0000 (16:31 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Jun 2014 15:01:18 +0000 (17:01 +0200)
sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java

index 49230376878b6f6cab8eeb8c6259dd7d65ea8139..bff09fd3f9d903788afdbdba13affe9cddf2511e 100644 (file)
@@ -88,10 +88,6 @@ public class MassUpdater {
     Connection writeConnection = null;
     PreparedStatement writeStatement = null;
     try {
-      writeConnection = db.getDataSource().getConnection();
-      writeConnection.setAutoCommit(false);
-      writeStatement = writeConnection.prepareStatement(converter.updateSql());
-
       readConnection = db.getDataSource().getConnection();
       readConnection.setAutoCommit(false);
 
@@ -104,6 +100,17 @@ public class MassUpdater {
         if (row == null) {
           continue;
         }
+
+        if (writeConnection==null) {
+          // do not open the write connection too early
+          // else if the select  on read connection is long, then mysql
+          // write connection fails with communication failure error because
+          // no activity during a long period
+          writeConnection = db.getDataSource().getConnection();
+          writeConnection.setAutoCommit(false);
+          writeStatement = writeConnection.prepareStatement(converter.updateSql());
+        }
+
         if (converter.convert(row, writeStatement)) {
           writeStatement.addBatch();
           writeStatement.clearParameters();