aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-20 16:31:13 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-06-20 17:01:18 +0200
commit7557461a362d3caad00a18d90b2052768e85aec6 (patch)
treec5e7a8f4f73c13e9df2e1134feef9b98f450ad9b /sonar-server
parent8f88f4d036262bf0606f11306cdef85f6e8214aa (diff)
downloadsonarqube-7557461a362d3caad00a18d90b2052768e85aec6.tar.gz
sonarqube-7557461a362d3caad00a18d90b2052768e85aec6.zip
SONAR-5394 open SQL write connection only on first statement
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
index 49230376878..bff09fd3f9d 100644
--- a/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
+++ b/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java
@@ -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();