]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23350 Fix ORA-1000 Maximum Number of Cursors Exceeded during measures migration
authorClaire Villard <claire.villard@sonarsource.com>
Thu, 10 Oct 2024 08:14:31 +0000 (10:14 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 10 Oct 2024 20:02:44 +0000 (20:02 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java

index 307d57507106f620fb231f414fc7a01cb96b10d0..1c79d9172949467145a8ecb08f56f2bdec6e4fb7 100644 (file)
@@ -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);
   }