2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.db.migrations.v43;
23 import com.google.common.annotations.VisibleForTesting;
24 import org.sonar.api.issue.Issue;
25 import org.sonar.api.utils.System2;
26 import org.sonar.core.persistence.Database;
27 import org.sonar.server.db.migrations.DatabaseMigration;
28 import org.sonar.server.db.migrations.MassUpdater;
29 import org.sonar.server.db.migrations.SqlUtil;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.sql.Timestamp;
37 * Used in the Active Record Migration 525
41 public class NotResolvedIssuesOnRemovedComponentsMigration implements DatabaseMigration {
43 private final System2 system2;
44 private final Database db;
46 public NotResolvedIssuesOnRemovedComponentsMigration(Database database, System2 system2) {
48 this.system2 = system2;
52 public void execute() {
53 new MassUpdater(db).execute(
54 new MassUpdater.InputLoader<Row>() {
56 public String selectSql() {
57 return "SELECT i.id FROM issues i " +
58 "INNER JOIN projects p on p.id=i.component_id " +
59 "WHERE p.enabled=${_false} AND i.resolution IS NULL ";
63 public Row load(ResultSet rs) throws SQLException {
65 row.id = SqlUtil.getLong(rs, 1);
69 new MassUpdater.InputConverter<Row>() {
71 public String updateSql() {
72 return "UPDATE issues SET status=?,resolution=?,updated_at=? WHERE id=?";
76 public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
77 updateStatement.setString(1, Issue.STATUS_CLOSED);
78 updateStatement.setString(2, Issue.RESOLUTION_REMOVED);
79 updateStatement.setTimestamp(3, new Timestamp(system2.now()));
80 updateStatement.setLong(4, row.id);
87 private static class Row {