diff options
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdater.java | 15 |
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(); |