@Override protected void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT e.id from events e where e.uuid is null"); massUpdate.update("UPDATE events SET uuid=? WHERE id=?"); massUpdate.rowPluralName("events"); massUpdate.execute(this::handle); }
private static void populateAnalysisUuid(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select distinct di.project_snapshot_id, s.uuid from duplications_index di" + " inner join snapshots s on s.id=di.project_snapshot_id" + " where di.analysis_uuid is null"); massUpdate.update("UPDATE duplications_index SET analysis_uuid=? WHERE project_snapshot_id=? and analysis_uuid is null"); massUpdate.rowPluralName("analysis uuid of duplications_index entries"); massUpdate.execute(PopulateComponentUuidAndAnalysisUuidOfDuplicationsIndex::handleAnalysisUuid); }
private static void deleteOrphans(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id from events e where" + " e.component_uuid is null" + " or not exists (select id from snapshots s where s.uuid = e.analysis_uuid)"); massUpdate.update("delete from events where id = ?"); massUpdate.rowPluralName("delete orphan events"); massUpdate.execute(PopulateEventsComponentUuid::handleDelete); }
private static void deleteRowsWithoutComponent(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select distinct gr.resource_id from group_roles gr where" + " gr.resource_id is not null" + " and not exists (select id from projects p where p.id = gr.resource_id)"); massUpdate.rowPluralName("rows without component"); massUpdate.update("delete from group_roles where resource_id = ?"); massUpdate.execute(CleanOrphanRowsInGroupRoles::handle); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT s.id from snapshots s where s.uuid is null"); massUpdate.update("UPDATE snapshots SET uuid=? WHERE id=?"); massUpdate.rowPluralName("snapshots"); massUpdate.execute(this::handle); }
private static void populateCeActivityTmpColumns(Context context, String rowPluralName, String sql) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select(sql); massUpdate.update("update ce_activity set tmp_component_uuid=?, tmp_main_component_uuid=? where uuid=?"); massUpdate.rowPluralName(rowPluralName); massUpdate.execute(PopulateTmpColumnsToCeActivity::handleUpdate); }
private static void deleteOrphansInCeChildTable(Context context, String childTableName) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select task_uuid from " + childTableName + " child where" + " not exists (select 1 from ce_activity a where a.uuid = child.task_uuid)" + " and not exists (select 1 from ce_queue q where q.uuid = child.task_uuid)"); massUpdate.rowPluralName("orphans rows in " + childTableName); massUpdate.update("delete from " + childTableName + " where task_uuid=?"); massUpdate.execute(CleanCeChildTablesOrphans::deleteByTaskUuid); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select distinct pm.snapshot_id, s.component_uuid from project_measures pm inner join snapshots s on s.id=pm.snapshot_id where pm.component_uuid is null"); massUpdate.update("UPDATE project_measures SET component_uuid=? WHERE snapshot_id=? and component_uuid is null"); massUpdate.rowPluralName("measures"); massUpdate.execute(this::handle); }
private static void deleteFromCeQueue(Context context, String pluralName, String sql) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select(sql); massUpdate.update("delete from ce_queue where uuid = ?"); massUpdate.rowPluralName(pluralName); massUpdate.execute(PopulateTmpColumnsToCeQueue::handleDelete); }
@Override protected void execute(DataChange.Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select distinct uuid from projects where copy_component_uuid is not null"); massUpdate.update("delete from project_measures where component_uuid=?"); massUpdate.execute((row, update) -> { update.setString(1, row.getString(1)); return true; }); } }
private static void populateUuidColumns(Context context, Map<Long, String> componentUuidById) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null"); massUpdate.update("UPDATE snapshots SET component_uuid=?, root_component_uuid=? WHERE id=?"); massUpdate.rowPluralName("snapshots"); massUpdate.execute((row, update) -> handle(componentUuidById, row, update)); }
private static void populateLastUsedColumn(Context context, Map<String, Long> lastAnalysisDatesByQualityProfileKey) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id, kee from rules_profiles where last_used is null"); massUpdate.update("update rules_profiles set last_used=? where id=?"); massUpdate.rowPluralName("rules_profiles"); massUpdate.execute((row, update) -> handle(lastAnalysisDatesByQualityProfileKey, row, update)); }
@Override protected void execute(Context context) throws SQLException { Map<String, Integer> ruleKeysById = context.prepareSelect("select id, plugin_name, plugin_rule_key from rules") .list(row -> new Rule(row.getInt(1), RuleKey.of(row.getString(2), row.getString(3)).toString())) .stream() .collect(Collectors.toMap(r -> r.ruleKey, r -> r.ruleId)); MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select kee,change_data from qprofile_changes"); massUpdate.update("update qprofile_changes set change_data=? where kee=?"); massUpdate.execute(((row, update) -> handle(row, update, ruleKeysById))); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id from loaded_templates where template_type like 'QUALITY_PROFILE.%'"); massUpdate.rowPluralName("loaded_templates"); massUpdate.update("delete from loaded_templates where id=?"); massUpdate.execute((row, update) -> { update.setLong(1, row.getLong(1)); return true; }); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT e.id from events e where e.snapshot_id is null"); massUpdate.update("DELETE from events WHERE id=?"); massUpdate.rowPluralName("no snapshot id events"); massUpdate.execute((row, update) -> { update.setLong(1, row.getLong(1)); return true; }); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id from project_measures where analysis_uuid is null"); massUpdate.update("delete from project_measures where id=?"); massUpdate.rowPluralName("measures"); massUpdate.execute((row, update) -> { update.setLong(1, row.getLong(1)); return true; }); }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT u.id, u.login FROM users u WHERE external_identity_provider IS NULL OR external_identity IS NULL"); massUpdate.update("UPDATE users SET external_identity_provider=?, external_identity=?, updated_at=? WHERE id=?"); massUpdate.rowPluralName("users"); massUpdate.execute(new MigrationHandler(system2.now())); }
private static void deleteRowsWithoutComponentUuid(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("SELECT id from duplications_index where component_uuid is null"); massUpdate.update("DELETE from duplications_index WHERE id=?"); massUpdate.rowPluralName("duplications index rows without component"); massUpdate.execute((row, update) -> { update.setLong(1, row.getLong(1)); return true; }); }
private static void deleteFromTable(Context context, String tableName) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id from " + tableName + " where role=?").setString(1, PERMISSION); massUpdate.update("delete from " + tableName + " where id=?"); massUpdate.rowPluralName(tableName); massUpdate.execute((row, update) -> { update.setLong(1, row.getLong(1)); return true; }); } }
@Override public void execute(Context context) throws SQLException { MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select("select id from rules_profiles where is_built_in is null"); massUpdate.rowPluralName("rules_profiles"); massUpdate.update("update rules_profiles set is_built_in=? where id=?"); massUpdate.execute((row, update) -> { update.setBoolean(1, false); update.setLong(2, row.getLong(1)); return true; }); }