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 resolution_key = :key
81 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
82 AND artifact_name = :artifactName AND occurrence BETWEEN :begin AND :end
83 ORDER BY occurrence DESC, creation_date DESC
87 fun findOccurrencesWithinRange(
88 @Param("key")key: String,
89 @Param("blueprintName")blueprintName: String,
90 @Param("blueprintVersion")blueprintVersion: String,
91 @Param("artifactName")artifactName: String,
92 @Param("begin")begin: Int,
94 ): List<ResourceResolution>
98 SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE resolution_key = :key
99 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
100 AND artifact_name = :artifactName
104 fun findMaxOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
105 @Param("key")key: String,
106 @Param("blueprintName")blueprintName: String,
107 @Param("blueprintVersion")blueprintVersion: String,
108 @Param("artifactName")artifactName: String
113 SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE blueprint_name = :blueprintName
114 AND blueprint_version = :blueprintVersion AND resource_id = :resourceId
115 AND resource_type = :resourceType
119 fun findMaxOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
120 @Param("blueprintName")blueprintName: String,
121 @Param("blueprintVersion")blueprintVersion: String,
122 @Param("resourceId")resourceId: String,
123 @Param("resourceType")resourceType: String
126 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
127 resolutionKey: String,
128 blueprintName: String,
129 blueprintVersion: String,
130 artifactPrefix: String
131 ): List<ResourceResolution>
133 fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
134 blueprintName: String,
135 blueprintVersion: String,
138 ): List<ResourceResolution>
140 fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
141 blueprintName: String?,
142 blueprintVersion: String?,
143 artifactName: String,
144 resolutionKey: String,
146 ): List<ResourceResolution>
148 fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
149 blueprintName: String?,
150 blueprintVersion: String?,
151 artifactName: String,
153 resourceType: String,
155 ): List<ResourceResolution>
158 fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
159 blueprintName: String,
160 blueprintVersion: String,
161 artifactName: String,
162 resolutionKey: String
166 fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceTypeAndResourceId(
167 blueprintName: String,
168 blueprintVersion: String,
169 artifactName: String,
170 resourceType: String,
178 DELETE FROM RESOURCE_RESOLUTION
179 WHERE resolution_key = :resolutionKey AND blueprint_name = :blueprintName
180 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
182 SELECT MAX(occurrence) - :lastN FROM (
183 SELECT occurrence from RESOURCE_RESOLUTION
184 WHERE resolution_key = :resolutionKey
185 AND blueprint_name = :blueprintName
186 AND blueprint_version = :blueprintVersion
187 AND artifact_name = :artifactName) AS o
192 fun deleteLastNOccurrences(
193 @Param("blueprintName") blueprintName: String,
194 @Param("blueprintVersion") blueprintVersion: String,
195 @Param("artifactName") artifactName: String,
196 @Param("resolutionKey") resolutionKey: String,
197 @Param("lastN") lastN: Int
204 DELETE FROM RESOURCE_RESOLUTION
205 WHERE resource_type = :resourceType AND resource_id = :resourceId
206 AND blueprint_name = :blueprintName
207 AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName
209 SELECT MAX(occurrence) - :lastN FROM (
210 SELECT occurrence FROM RESOURCE_RESOLUTION
211 WHERE resource_type = :resourceType
212 AND resource_id = :resourceId
213 AND blueprint_name = :blueprintName
214 AND blueprint_version = :blueprintVersion
215 AND artifact_name = :artifactName) AS o
220 fun deleteLastNOccurrences(
221 @Param("blueprintName") blueprintName: String,
222 @Param("blueprintVersion") blueprintVersion: String,
223 @Param("artifactName") artifactName: String,
224 @Param("resourceType") resourceType: String,
225 @Param("resourceId") resourceId: String,
226 @Param("lastN") lastN: Int