From af66bd7b20a5efb5f6f2b73c0fe2adcad93b59b6 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 5 Nov 2014 15:01:14 +0100 Subject: [PATCH] SONAR-5838 Migration of custom rules without parameter values is failing on Oracle --- .../server/db/migrations/MassUpdate.java | 8 ++++---- ...dMissingCustomRuleParametersMigration.java | 19 +++++++++++++++++++ .../migration/v45/Migration45Mapper.java | 7 +++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java index 8013d9cff81..845b22c5d84 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MassUpdate.java @@ -99,13 +99,13 @@ public class MassUpdate { } } - static class ProgressTask extends TimerTask { + public static class ProgressTask extends TimerTask { private static final Logger LOGGER = LoggerFactory.getLogger("DbMigration"); - private static final long PERIOD_MS = 60000L; + public static final long PERIOD_MS = 60000L; private final AtomicLong counter; private String rowName = "rows"; - ProgressTask(AtomicLong counter) { + public ProgressTask(AtomicLong counter) { this.counter = counter; } @@ -118,7 +118,7 @@ public class MassUpdate { log(); } - void log() { + public void log() { LOGGER.info(String.format("%d %s processed", counter.get(), rowName)); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java index 48aad8fe922..4012a7321b9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java @@ -31,11 +31,15 @@ import org.sonar.core.persistence.migration.v45.Rule; import org.sonar.core.persistence.migration.v45.RuleParameter; import org.sonar.server.db.DbClient; import org.sonar.server.db.migrations.DatabaseMigration; +import org.sonar.server.db.migrations.MassUpdate; import javax.annotation.Nullable; + import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Timer; +import java.util.concurrent.atomic.AtomicLong; /** * See http://jira.codehaus.org/browse/SONAR-5575 @@ -49,6 +53,10 @@ public class AddMissingCustomRuleParametersMigration implements DatabaseMigratio private final DbClient db; private final System2 system; + private final AtomicLong counter = new AtomicLong(0L); + private final MassUpdate.ProgressTask progressTask = new MassUpdate.ProgressTask(counter); + + public AddMissingCustomRuleParametersMigration(DbClient db, System2 system) { this.db = db; this.system = system; @@ -56,6 +64,9 @@ public class AddMissingCustomRuleParametersMigration implements DatabaseMigratio @Override public void execute() { + Timer timer = new Timer("Db Migration Progress"); + timer.schedule(progressTask, MassUpdate.ProgressTask.PERIOD_MS, MassUpdate.ProgressTask.PERIOD_MS); + DbSession session = db.openSession(false); try { Migration45Mapper mapper = session.getMapper(Migration45Mapper.class); @@ -95,14 +106,22 @@ public class AddMissingCustomRuleParametersMigration implements DatabaseMigratio // Update updated at date of custom rule in order to allow E/S indexation mapper.updateRuleUpdateAt(customRuleId, new Date(system.now())); + + counter.getAndIncrement(); } } } } session.commit(); + + // log the total number of process rows + progressTask.log(); } finally { session.close(); + + timer.cancel(); + timer.purge(); } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java index 4f78491095a..a6c41647f4c 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java @@ -19,10 +19,7 @@ */ package org.sonar.core.persistence.migration.v45; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Result; -import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.*; import java.util.Date; import java.util.List; @@ -53,9 +50,11 @@ public interface Migration45Mapper { @Insert("INSERT INTO rules_parameters (rule_id, name, param_type, default_value, description)" + " VALUES (#{ruleId}, #{name}, #{type}, #{defaultValue}, #{description})") + @Options(useGeneratedKeys = false) void insertRuleParameter(RuleParameter ruleParameter); @Insert("UPDATE rules SET updated_at=#{date} WHERE id=#{id}") + @Options(useGeneratedKeys = false) void updateRuleUpdateAt(@Param("id") Integer ruleId, @Param("date") Date updatedAt); } -- 2.39.5