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.Query
20 import org.springframework.data.repository.query.Param
21 import org.springframework.stereotype.Repository
22 import javax.transaction.Transactional
25 interface TemplateResolutionRepository : JpaRepository<TemplateResolution, String> {
29 SELECT * FROM TEMPLATE_RESOLUTION
30 WHERE resource_type = :resourceType AND resource_id = :resourceId
31 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
32 AND artifact_name = :artifactName AND occurrence = :occurrence
33 ORDER BY creation_date DESC LIMIT 1
37 fun findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
40 blueprintName: String?,
41 blueprintVersion: String?,
44 ): TemplateResolution?
48 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
49 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
50 AND artifact_name = :artifactName AND occurrence = :occurrence
51 ORDER BY creation_date DESC LIMIT 1
55 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
57 blueprintName: String?,
58 blueprintVersion: String?,
61 ): TemplateResolution?
65 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
66 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
67 AND artifact_name = :artifactName
68 AND occurrence <= :firstN
72 fun findFirstNOccurrences(
73 @Param("key")key: String,
74 @Param("blueprintName")blueprintName: String,
75 @Param("blueprintVersion")blueprintVersion: String,
76 @Param("artifactName")artifactName: String,
77 @Param("firstN")begin: Int
78 ): List<TemplateResolution>
82 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
83 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
84 AND artifact_name = :artifactName
86 select max(occurrence) - :lastN from RESOURCE_RESOLUTION
87 WHERE resolution_key = :key
88 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
89 AND artifact_name = :artifactName)
90 ORDER BY occurrence DESC, creation_date DESC
94 fun findLastNOccurrences(
95 @Param("key")key: String,
96 @Param("blueprintName")blueprintName: String,
97 @Param("blueprintVersion")blueprintVersion: String,
98 @Param("artifactName")artifactName: String,
99 @Param("lastN")begin: Int
100 ): List<TemplateResolution>
104 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
105 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
106 AND artifact_name = :artifactName
107 AND occurrence BETWEEN :begin AND :end
108 ORDER BY occurrence DESC, creation_date DESC
112 fun findOccurrencesWithinRange(
113 @Param("key")key: String,
114 @Param("blueprintName")blueprintName: String,
115 @Param("blueprintVersion")blueprintVersion: String,
116 @Param("artifactName")artifactName: String,
117 @Param("begin")begin: Int,
118 @Param("end")end: Int
119 ): List<TemplateResolution>
121 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
122 resolutionKey: String,
123 blueprintName: String,
124 blueprintVersion: String,
125 artifactPrefix: String
126 ): List<TemplateResolution>
129 "select tr.resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.artifactName = :artifactName and tr.occurrence = :occurrence"
131 fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
132 @Param("blueprintName") blueprintName: String?,
133 @Param("blueprintVersion") blueprintVersion: String?,
134 @Param("artifactName") artifactName: String,
135 @Param("occurrence") occurrence: Int
139 "select tr.artifactName as artifactName, tr.resolutionKey as resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.occurrence = :occurrence"
141 fun findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersionAndOccurrence(
142 @Param("blueprintName") blueprintName: String?,
143 @Param("blueprintVersion") blueprintVersion: String?,
144 @Param("occurrence") occurrence: Int
145 ): List<TemplateResolutionSelector>?
148 fun deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
150 resourceType: String,
151 blueprintName: String?,
152 blueprintVersion: String?,
153 artifactName: String,
158 fun deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
160 blueprintName: String?,
161 blueprintVersion: String?,
162 artifactName: String,