}
}
- 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;
}
log();
}
- void log() {
+ public void log() {
LOGGER.info(String.format("%d %s processed", counter.get(), rowName));
}
}
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
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;
@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);
// 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();
}
}
*/
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;
@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);
}