From: Lukasz Jarocki Date: Mon, 8 May 2023 07:44:26 +0000 (+0200) Subject: SONAR-19125 fixed an issue where one of 10.0 migration did not work on Oracle Databases X-Git-Tag: 10.1.0.73491~333 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e3312c7db30756592236f803c5a9d37bc6de5483;p=sonarqube.git SONAR-19125 fixed an issue where one of 10.0 migration did not work on Oracle Databases --- diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfiles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfiles.java index 38283a3761c..60733dcc5c9 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfiles.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/RemoveOrphanRulesFromQualityProfiles.java @@ -24,8 +24,9 @@ import org.sonar.api.utils.System2; import org.sonar.core.util.UuidFactory; import org.sonar.db.Database; import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; import org.sonar.server.platform.db.migration.step.Select; -import org.sonar.server.platform.db.migration.step.Upsert; +import org.sonar.server.platform.db.migration.step.SqlStatement; public class RemoveOrphanRulesFromQualityProfiles extends DataChange { @@ -40,36 +41,38 @@ public class RemoveOrphanRulesFromQualityProfiles extends DataChange { @Override protected void execute(Context context) throws SQLException { - Select select = context.prepareSelect("select ar.uuid, ar.profile_uuid, ar.rule_uuid from rules_profiles rp " + + final String SELECT_QUERY = "select ar.uuid, ar.profile_uuid, ar.rule_uuid from rules_profiles rp " + "inner join active_rules ar on ar.profile_uuid = rp.uuid " + "inner join rules r on r.uuid = ar.rule_uuid " + - "where rp.language != r.language"); - select.scroll(row -> process(context, row)); - } + "where rp.language != r.language"; + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate.select(SELECT_QUERY); + + final String UPDATE_QUERY = """ + INSERT INTO qprofile_changes + (kee, rules_profile_uuid, change_type, created_at, user_uuid, change_data) + VALUES(?, ?, ?, ?, ?, ?) + """; + massUpdate.update(UPDATE_QUERY); + massUpdate.update("delete from active_rules where uuid = ?"); - private void process(Context context, Select.Row row) throws SQLException { - Upsert insertQualityProfileChange = insertQualityProfileChange(context, row); - Upsert deleteActiveRule = deleteActiveRule(context, row); - insertQualityProfileChange.commit(); - deleteActiveRule.commit(); + massUpdate.execute((row, update, index) -> { + if (index == 0) { + prepareUpdateForQProfileChanges(row, update); + } + if (index == 1) { + update.setString(1, row.getString(1)); + } + return true; + }); } - private Upsert insertQualityProfileChange(Context context, Select.Row row) throws SQLException { - return context.prepareUpsert("INSERT INTO qprofile_changes " + - "(kee, rules_profile_uuid, change_type, created_at, user_uuid, change_data) " + - "VALUES(?, ?, ?, ?, ?, ?);") - .setString(1, uuidFactory.create()) - .setString(2, row.getString(2)) + private void prepareUpdateForQProfileChanges(Select.Row selectedRow, SqlStatement update) throws SQLException { + update.setString(1, uuidFactory.create()) + .setString(2, selectedRow.getString(2)) .setString(3, "DEACTIVATED") .setLong(4, system2.now()) .setString(5, null) - .setString(6, "ruleUuid=" + row.getString(3)) - .execute(); - } - - private static Upsert deleteActiveRule(Context context, Select.Row row) throws SQLException { - return context.prepareUpsert("delete from active_rules where uuid = ?") - .setString(1, row.getString(1)) - .execute(); + .setString(6, "ruleUuid=" + selectedRow.getString(3)); } }