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>
if (lastNOccurrences < 0) {
throw IllegalArgumentException("last N occurrences must be a positive integer")
}
- resourceResolutionRepository.deleteLastNOccurences(
+ resourceResolutionRepository.deleteLastNOccurrences(
blueprintName,
blueprintVersion,
artifactName,
if (lastNOccurrences < 0) {
throw IllegalArgumentException("last N occurrences must be a positive integer")
}
- resourceResolutionRepository.deleteLastNOccurences(
+ resourceResolutionRepository.deleteLastNOccurrences(
blueprintName,
blueprintVersion,
artifactName,
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,
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,
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
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
)
@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(
@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(