From 598bdb410359f5bc198652b6dc802d0b1e2f8758 Mon Sep 17 00:00:00 2001 From: Claire Villard Date: Thu, 10 Oct 2024 10:14:31 +0200 Subject: [PATCH] SONAR-23350 Fix ORA-1000 Maximum Number of Cursors Exceeded during measures migration --- ...AbstractMigrateLiveMeasuresToMeasures.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java index 307d5750710..1c79d917294 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java @@ -77,25 +77,25 @@ public abstract class AbstractMigrateLiveMeasuresToMeasures extends DataChange { private String getSelectUuidQuery() { return format(""" - SELECT uuid - FROM %s - WHERE measures_migrated = ? - """, tableName); + SELECT uuid + FROM %s + WHERE measures_migrated = ? + """, tableName); } private String getCountQuery() { return format(""" - SELECT count(uuid) - FROM %s - """, tableName); + SELECT count(uuid) + FROM %s + """, tableName); } private String getUpdateFlagQuery() { return format(""" - UPDATE %s - SET measures_migrated = ? - WHERE uuid = ? - """, tableName); + UPDATE %s + SET measures_migrated = ? + WHERE uuid = ? + """, tableName); } @Override @@ -149,20 +149,23 @@ public abstract class AbstractMigrateLiveMeasuresToMeasures extends DataChange { }); // insert the last component if (!measureValues.isEmpty()) { - Upsert measureInsert = context.prepareUpsert(INSERT_QUERY); - preparePersistMeasure(uuid, measureInsert, componentUuid, measureValues); - measureInsert - .execute() - .commit(); + try (Upsert measureInsert = context.prepareUpsert(INSERT_QUERY)) { + preparePersistMeasure(uuid, measureInsert, componentUuid, measureValues); + measureInsert + .execute() + .commit(); + } } LOGGER.debug("Flagging migration done for {} {}...", item, uuid); - context.prepareUpsert(getUpdateFlagQuery()) - .setBoolean(1, true) - .setString(2, uuid) - .execute() - .commit(); + try (Upsert flagUpdate = context.prepareUpsert(getUpdateFlagQuery())) { + flagUpdate + .setBoolean(1, true) + .setString(2, uuid) + .execute() + .commit(); + } LOGGER.debug("Migration finished for {} {}", item, uuid); } -- 2.39.5