3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program 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 * This program 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.
20 package org.sonar.db.version.v60;
22 import java.sql.SQLException;
23 import org.sonar.db.Database;
24 import org.sonar.db.version.BaseDataChange;
25 import org.sonar.db.version.MassUpdate;
26 import org.sonar.db.version.Select;
27 import org.sonar.db.version.SqlStatement;
29 public class PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex extends BaseDataChange {
31 public PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex(Database db) {
36 public void execute(Context context) throws SQLException {
37 populateComponentUuid(context);
38 populateAnalysisUuid(context);
41 private void populateComponentUuid(Context context) throws SQLException {
42 MassUpdate massUpdate = context.prepareMassUpdate();
43 massUpdate.select("select distinct di.snapshot_id, s.component_uuid from duplications_index di" +
44 " inner join snapshots s on s.id=di.snapshot_id" +
45 " where di.component_uuid is null");
46 massUpdate.update("UPDATE duplications_index SET component_uuid=? WHERE snapshot_id=? and component_uuid is null");
47 massUpdate.rowPluralName("component uuid of duplications_index entries");
48 massUpdate.execute(PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex::handleComponentUuid);
51 private static boolean handleComponentUuid(Select.Row row, SqlStatement update) throws SQLException {
52 long snapshotId = row.getLong(1);
53 String componentUuid = row.getString(2);
55 update.setString(1, componentUuid);
56 update.setLong(2, snapshotId);
61 public void populateAnalysisUuid(Context context) throws SQLException {
62 MassUpdate massUpdate = context.prepareMassUpdate();
63 massUpdate.select("select distinct di.project_snapshot_id, s.uuid from duplications_index di" +
64 " inner join snapshots s on s.id=di.project_snapshot_id" +
65 " where di.analysis_uuid is null");
66 massUpdate.update("UPDATE duplications_index SET analysis_uuid=? WHERE project_snapshot_id=? and analysis_uuid is null");
67 massUpdate.rowPluralName("analysis uuid of duplications_index entries");
68 massUpdate.execute(PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex::handleAnalysisUuid);
71 private static boolean handleAnalysisUuid(Select.Row row, SqlStatement update) throws SQLException {
72 long projectSnapshotId = row.getLong(1);
73 String snapshotUuid = row.getString(2);
75 update.setString(1, snapshotUuid);
76 update.setLong(2, projectSnapshotId);