2 * Copyright (C) 2019 Bell Canada.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
18 import org.springframework.data.jpa.repository.JpaRepository
19 import org.springframework.data.jpa.repository.Modifying
20 import org.springframework.data.jpa.repository.Query
21 import org.springframework.data.repository.query.Param
22 import org.springframework.stereotype.Repository
23 import javax.transaction.Transactional
26 interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
29 value = "SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName AND name = :name ORDER BY occurrence DESC, creation_date DESC LIMIT 1",
32 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
33 @Param("key")key: String,
34 @Param("blueprintName")blueprintName: String,
35 @Param("blueprintVersion")blueprintVersion: String,
36 @Param("artifactName")artifactName: String,
37 @Param("name")name: String
38 ): ResourceResolution?
42 SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key
43 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
44 AND artifact_name = :artifactName AND occurrence <= :firstN
48 fun findFirstNOccurrences(
49 @Param("key")key: String,
50 @Param("blueprintName")blueprintName: String,
51 @Param("blueprintVersion")blueprintVersion: String,
52 @Param("artifactName")artifactName: String,
53 @Param("firstN")begin: Int
54 ): List<ResourceResolution>
58 SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key
59 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
60 AND artifact_name = :artifactName
62 select max(occurrence) - :lastN from RESOURCE_RESOLUTION
63 WHERE resolution_key = :key AND blueprint_name = :blueprintName
64 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
66 ORDER BY occurrence DESC, creation_date DESC
70 fun findLastNOccurrences(
71 @Param("key")key: String,
72 @Param("blueprintName")blueprintName: String,
73 @Param("blueprintVersion")blueprintVersion: String,
74 @Param("artifactName")artifactName: String,
75 @Param("lastN")begin: Int
76 ): List<ResourceResolution>
80 SELECT * FROM RESOURCE_RESOLUTION WHERE resource_id = :resourceId
81 AND resource_type =:resourceType AND blueprint_name = :blueprintName
82 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
84 select max(occurrence) - :lastN from RESOURCE_RESOLUTION
85 WHERE resource_id = :resourceId
86 AND resource_type =:resourceType AND blueprint_name = :blueprintName
87 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName)
88 ORDER BY occurrence DESC, creation_date DESC
92 fun findLastNOccurrences(
93 @Param("resourceId")resourceId: String,
94 @Param("resourceType")resourceType: String,
95 @Param("blueprintName")blueprintName: String,
96 @Param("blueprintVersion")blueprintVersion: String,
97 @Param("artifactName")artifactName: String,
98 @Param("lastN")begin: Int
99 ): List<ResourceResolution>
103 SELECT * FROM RESOURCE_RESOLUTION WHERE resolution_key = :key
104 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
105 AND artifact_name = :artifactName AND occurrence BETWEEN :begin AND :end
106 ORDER BY occurrence DESC, creation_date DESC
110 fun findOccurrencesWithinRange(
111 @Param("key")key: String,
112 @Param("blueprintName")blueprintName: String,
113 @Param("blueprintVersion")blueprintVersion: String,
114 @Param("artifactName")artifactName: String,
115 @Param("begin")begin: Int,
116 @Param("end")end: Int
117 ): List<ResourceResolution>
121 SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE resolution_key = :key
122 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
123 AND artifact_name = :artifactName
127 fun findMaxOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
128 @Param("key")key: String,
129 @Param("blueprintName")blueprintName: String,
130 @Param("blueprintVersion")blueprintVersion: String,
131 @Param("artifactName")artifactName: String
136 SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE blueprint_name = :blueprintName
137 AND blueprint_version = :blueprintVersion AND resource_id = :resourceId
138 AND resource_type = :resourceType
142 fun findMaxOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
143 @Param("blueprintName")blueprintName: String,
144 @Param("blueprintVersion")blueprintVersion: String,
145 @Param("resourceId")resourceId: String,
146 @Param("resourceType")resourceType: String
149 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
150 resolutionKey: String,
151 blueprintName: String,
152 blueprintVersion: String,
153 artifactPrefix: String
154 ): List<ResourceResolution>
156 fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
157 blueprintName: String,
158 blueprintVersion: String,
161 ): List<ResourceResolution>
163 fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
164 blueprintName: String?,
165 blueprintVersion: String?,
166 artifactName: String,
167 resolutionKey: String,
169 ): List<ResourceResolution>
171 fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
172 blueprintName: String?,
173 blueprintVersion: String?,
174 artifactName: String,
176 resourceType: String,
178 ): List<ResourceResolution>
181 fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
182 blueprintName: String,
183 blueprintVersion: String,
184 artifactName: String,
185 resolutionKey: String
189 fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceTypeAndResourceId(
190 blueprintName: String,
191 blueprintVersion: String,
192 artifactName: String,
193 resourceType: String,
201 DELETE FROM RESOURCE_RESOLUTION
202 WHERE resolution_key = :resolutionKey AND blueprint_name = :blueprintName
203 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
205 SELECT MAX(occurrence) - :lastN FROM (
206 SELECT occurrence from RESOURCE_RESOLUTION
207 WHERE resolution_key = :resolutionKey
208 AND blueprint_name = :blueprintName
209 AND blueprint_version = :blueprintVersion
210 AND artifact_name = :artifactName) AS o
215 fun deleteLastNOccurrences(
216 @Param("blueprintName") blueprintName: String,
217 @Param("blueprintVersion") blueprintVersion: String,
218 @Param("artifactName") artifactName: String,
219 @Param("resolutionKey") resolutionKey: String,
220 @Param("lastN") lastN: Int
227 DELETE FROM RESOURCE_RESOLUTION
228 WHERE resource_type = :resourceType AND resource_id = :resourceId
229 AND blueprint_name = :blueprintName
230 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
232 SELECT MAX(occurrence) - :lastN FROM (
233 SELECT occurrence FROM RESOURCE_RESOLUTION
234 WHERE resource_type = :resourceType
235 AND resource_id = :resourceId
236 AND blueprint_name = :blueprintName
237 AND blueprint_version = :blueprintVersion
238 AND artifact_name = :artifactName) AS o
243 fun deleteLastNOccurrences(
244 @Param("blueprintName") blueprintName: String,
245 @Param("blueprintVersion") blueprintVersion: String,
246 @Param("artifactName") artifactName: String,
247 @Param("resourceType") resourceType: String,
248 @Param("resourceId") resourceId: String,
249 @Param("lastN") lastN: Int