Change SQL query syntax for delete resource/template 07/130207/4
authorJozsef Csongvai <jozsef.csongvai@bell.ca>
Wed, 15 Jun 2022 18:26:21 +0000 (14:26 -0400)
committerkuldipr <kuldip.rai@amdocs.com>
Wed, 31 Aug 2022 21:10:23 +0000 (17:10 -0400)
The delete query does not work with Mariadb version 10.1.24.
Changed the syntax so that it will work with both older and newer
versions. Typo in method names has been fixed as well.

Issue-ID: CCSDK-3735
Change-Id: I225752d62068e5aa44354624aa6542a4f4bae73b
Signed-off-by: kuldipr <kuldip.rai@amdocs.com>
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt

index 3041fa7..aa7b61f 100644 (file)
@@ -303,7 +303,7 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
         if (lastNOccurrences < 0) {
             throw IllegalArgumentException("last N occurrences must be a positive integer")
         }
-        resourceResolutionRepository.deleteLastNOccurences(
+        resourceResolutionRepository.deleteLastNOccurrences(
             blueprintName,
             blueprintVersion,
             artifactName,
@@ -341,7 +341,7 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
         if (lastNOccurrences < 0) {
             throw IllegalArgumentException("last N occurrences must be a positive integer")
         }
-        resourceResolutionRepository.deleteLastNOccurences(
+        resourceResolutionRepository.deleteLastNOccurrences(
             blueprintName,
             blueprintVersion,
             artifactName,
index 30969f1..9317a71 100644 (file)
@@ -179,13 +179,17 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
         WHERE resolution_key = :resolutionKey AND blueprint_name = :blueprintName
             AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
             AND occurrence > (
-                SELECT max(occurrence) - :lastN FROM RESOURCE_RESOLUTION
-                WHERE resolution_key = :resolutionKey AND blueprint_name = :blueprintName
-                    AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName)
+                SELECT MAX(occurrence) - :lastN FROM (
+                    SELECT occurrence from RESOURCE_RESOLUTION
+                    WHERE resolution_key = :resolutionKey
+                        AND blueprint_name = :blueprintName
+                        AND blueprint_version = :blueprintVersion
+                        AND artifact_name = :artifactName) AS o
+                )
     """,
         nativeQuery = true
     )
-    fun deleteLastNOccurences(
+    fun deleteLastNOccurrences(
         @Param("blueprintName") blueprintName: String,
         @Param("blueprintVersion") blueprintVersion: String,
         @Param("artifactName") artifactName: String,
@@ -202,14 +206,18 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
             AND blueprint_name = :blueprintName
             AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
             AND occurrence > (
-                SELECT max(occurrence) - :lastN FROM RESOURCE_RESOLUTION
-                WHERE resource_type = :resourceType AND resource_id = :resourceId
-                    AND blueprint_name = :blueprintName
-                    AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName)
+                SELECT MAX(occurrence) - :lastN FROM (
+                    SELECT occurrence FROM RESOURCE_RESOLUTION
+                    WHERE resource_type = :resourceType
+                        AND resource_id = :resourceId
+                        AND blueprint_name = :blueprintName
+                        AND blueprint_version = :blueprintVersion
+                        AND artifact_name = :artifactName) AS o
+                )
     """,
         nativeQuery = true
     )
-    fun deleteLastNOccurences(
+    fun deleteLastNOccurrences(
         @Param("blueprintName") blueprintName: String,
         @Param("blueprintVersion") blueprintVersion: String,
         @Param("artifactName") artifactName: String,
index 1ee9f79..049e713 100644 (file)
@@ -189,9 +189,12 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin
             AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
             AND artifact_name = :artifactName
             AND occurrence > (
-                SELECT MAX(occurrence) - :lastN FROM TEMPLATE_RESOLUTION
-                WHERE resolution_key = :resolutionKey AND blueprint_name = :blueprintName
-                    AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
+                SELECT MAX(occurrence) - :lastN FROM (
+                    SELECT occurrence FROM TEMPLATE_RESOLUTION
+                    WHERE resolution_key = :resolutionKey
+                        AND blueprint_name = :blueprintName
+                        AND blueprint_version = :blueprintVersion
+                        AND artifact_name = :artifactName) AS o
                 )
     """,
         nativeQuery = true
@@ -212,11 +215,14 @@ interface TemplateResolutionRepository : JpaRepository<TemplateResolution, Strin
             AND resource_id = :resourceId AND artifact_name = :artifactName
             AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
             AND occurrence > (
-                SELECT MAX(occurrence) - :lastN FROM TEMPLATE_RESOLUTION
-                WHERE resource_type = :resourceType
-                    AND resource_id = :resourceId AND blueprint_name = :blueprintName
-                    AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
-            )
+                SELECT MAX(occurrence) - :lastN FROM (
+                    SELECT occurrence FROM TEMPLATE_RESOLUTION
+                    WHERE resource_type = :resourceType
+                        AND resource_id = :resourceId
+                        AND blueprint_name = :blueprintName
+                        AND blueprint_version = :blueprintVersion
+                        AND artifact_name = :artifactName) AS o
+                )
     """,
         nativeQuery = true
     )
index 69e7a64..825b86e 100644 (file)
@@ -336,7 +336,7 @@ open class ResourceResolutionDBServiceTest {
     @Test
     fun deleteResourcesResolutionKeyLastN() {
         every {
-            resourceResolutionRepository.deleteLastNOccurences(blueprintName, blueprintVersion, artifactPrefix, resolutionKey, 1)
+            resourceResolutionRepository.deleteLastNOccurrences(blueprintName, blueprintVersion, artifactPrefix, resolutionKey, 1)
         } returns 4
         runBlocking {
             val res = resourceResolutionDBService.deleteResources(
@@ -362,7 +362,7 @@ open class ResourceResolutionDBServiceTest {
     @Test
     fun deleteResourcesResourceIdAndTypeLastN() {
         every {
-            resourceResolutionRepository.deleteLastNOccurences(blueprintName, blueprintVersion, artifactPrefix, resourceType, resourceId, 2)
+            resourceResolutionRepository.deleteLastNOccurrences(blueprintName, blueprintVersion, artifactPrefix, resourceType, resourceId, 2)
         } returns 6
         runBlocking {
             val res = resourceResolutionDBService.deleteResources(