]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4996 Improve Java migrations performance
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 3 Mar 2014 09:20:13 +0000 (10:20 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 3 Mar 2014 09:20:23 +0000 (10:20 +0100)
sonar-server/src/main/java/org/sonar/server/db/migrations/debt/DevelopmentCostMeasuresMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/debt/IssueChangelogMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/debt/IssueMigration.java
sonar-server/src/main/java/org/sonar/server/db/migrations/debt/MassUpdater.java
sonar-server/src/main/java/org/sonar/server/db/migrations/debt/TechnicalDebtMeasuresMigration.java

index d8778800f1cda72da5498f97ebf6ffe8237b296d..37496d84deb1f5aec756fe5e1368b45cab0efeee 100644 (file)
@@ -83,9 +83,9 @@ public class DevelopmentCostMeasuresMigration implements DatabaseMigration {
           if (row.value != null) {
             statement.setString(1, convertDebtForDays(row.value));
           } else {
-            statement.setNull(1, Types.NULL);
+            statement.setNull(1, Types.DOUBLE);
           }
-          statement.setDouble(2, row.id);
+          statement.setLong(2, row.id);
         }
       }
     );
@@ -99,7 +99,7 @@ public class DevelopmentCostMeasuresMigration implements DatabaseMigration {
     return Long.toString(workDurationConvertor.createFromDays(data));
   }
 
-  private class Row {
+  private static class Row {
     Long id;
     Double value;
   }
index 1158759a84b92caf418bdf34b5afd973e458d5a3..4434de3d08b5ac0c030cbb34ee7c3fb18130666e 100644 (file)
@@ -89,10 +89,10 @@ public class IssueChangelogMigration implements DatabaseMigration {
           if (row.changeData != null) {
             statement.setString(1, convertChangelog(row.changeData));
           } else {
-            statement.setNull(1, Types.NULL);
+            statement.setNull(1, Types.VARCHAR);
           }
           statement.setDate(2, new Date(system2.now()));
-          statement.setDouble(3, row.id);
+          statement.setLong(3, row.id);
         }
       }
     );
@@ -122,7 +122,7 @@ public class IssueChangelogMigration implements DatabaseMigration {
     return sb.toString();
   }
 
-  private class Row {
+  private static class Row {
     Long id;
     String changeData;
   }
index e1b09b9e2c781011586eef28e941eb969dbdc145..777b82d4141e459b88842f57189cba1adc44ac78 100644 (file)
@@ -86,13 +86,13 @@ public class IssueMigration implements DatabaseMigration {
         public void convert(Row row, PreparedStatement statement) throws SQLException {
           statement.setLong(1, workDurationConvertor.createFromLong(row.debt));
           statement.setDate(2, new Date(system2.now()));
-          statement.setDouble(3, row.id);
+          statement.setLong(3, row.id);
         }
       }
     );
   }
 
-  private class Row {
+  private static class Row {
     Long id;
     Long debt;
   }
index 28bcb0c1bdb25bd172dcc9107982754523c2f144..0ca0e05263d7877da98081ec6ca2636f550ba957 100644 (file)
@@ -58,6 +58,7 @@ public class MassUpdater {
   }
 
   public <S> void execute(InputLoader<S> inputLoader, InputConverter<S> converter) {
+    int count = 0;
     try {
       Connection readConnection = db.getDataSource().getConnection();
       Statement stmt = null;
@@ -86,6 +87,7 @@ public class MassUpdater {
           writeStatement.addBatch();
 
           cursor++;
+          count++;
           if (cursor == GROUP_SIZE) {
             writeStatement.executeBatch();
             writeConnection.commit();
@@ -96,13 +98,14 @@ public class MassUpdater {
           writeStatement.executeBatch();
           writeConnection.commit();
         }
-
       } finally {
         if (writeStatement != null) {
           writeStatement.close();
         }
         DbUtils.closeQuietly(writeConnection);
         DbUtils.closeQuietly(readConnection, stmt, rs);
+
+        logger.info("{} rows have been updated", count);
       }
     } catch (SQLException e) {
       logger.error(FAILURE_MESSAGE, e);
index c43be700ced220c0c20ecf541e44a1fccdc79ce3..56fb03d76fad1ab8de45550458c4c0a58b50a678 100644 (file)
@@ -101,7 +101,7 @@ public class TechnicalDebtMeasuresMigration implements DatabaseMigration {
           setDouble(statement, 4, row.var3);
           setDouble(statement, 5, row.var4);
           setDouble(statement, 6, row.var5);
-          statement.setDouble(7, row.id);
+          statement.setLong(7, row.id);
         }
       }
     );
@@ -111,7 +111,7 @@ public class TechnicalDebtMeasuresMigration implements DatabaseMigration {
     if (value != null) {
       statement.setDouble(index, convertDebtForDays(value));
     } else {
-      statement.setNull(index, Types.NULL);
+      statement.setNull(index, Types.DOUBLE);
     }
   }
 
@@ -119,7 +119,7 @@ public class TechnicalDebtMeasuresMigration implements DatabaseMigration {
     return workDurationConvertor.createFromDays(data);
   }
 
-  private class Row {
+  private static class Row {
     Long id;
     Double value;
     Double var1;