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> {
27 fun findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
30 blueprintName: String?,
31 blueprintVersion: String?,
34 ): TemplateResolution?
36 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
38 blueprintName: String?,
39 blueprintVersion: String?,
42 ): TemplateResolution?
46 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
47 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
48 AND artifact_name = :artifactName
49 AND occurrence <= :firstN
53 fun findFirstNOccurrences(
54 @Param("key")key: String,
55 @Param("blueprintName")blueprintName: String,
56 @Param("blueprintVersion")blueprintVersion: String,
57 @Param("artifactName")artifactName: String,
58 @Param("firstN")begin: Int
59 ): List<TemplateResolution>
63 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
64 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
65 AND artifact_name = :artifactName
67 select max(occurrence) - :lastN from RESOURCE_RESOLUTION
68 WHERE resolution_key = :key
69 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
70 AND artifact_name = :artifactName)
71 ORDER BY occurrence DESC, creation_date DESC
75 fun findLastNOccurrences(
76 @Param("key")key: String,
77 @Param("blueprintName")blueprintName: String,
78 @Param("blueprintVersion")blueprintVersion: String,
79 @Param("artifactName")artifactName: String,
80 @Param("lastN")begin: Int
81 ): List<TemplateResolution>
85 SELECT * FROM TEMPLATE_RESOLUTION WHERE resolution_key = :key
86 AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion
87 AND artifact_name = :artifactName
88 AND occurrence BETWEEN :begin AND :end
89 ORDER BY occurrence DESC, creation_date DESC
93 fun findOccurrencesWithinRange(
94 @Param("key")key: String,
95 @Param("blueprintName")blueprintName: String,
96 @Param("blueprintVersion")blueprintVersion: String,
97 @Param("artifactName")artifactName: String,
98 @Param("begin")begin: Int,
100 ): List<TemplateResolution>
102 fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
103 resolutionKey: String,
104 blueprintName: String,
105 blueprintVersion: String,
106 artifactPrefix: String
107 ): List<TemplateResolution>
110 "select tr.resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.artifactName = :artifactName and tr.occurrence = :occurrence"
112 fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
113 @Param("blueprintName") blueprintName: String?,
114 @Param("blueprintVersion") blueprintVersion: String?,
115 @Param("artifactName") artifactName: String,
116 @Param("occurrence") occurrence: Int
120 "select tr.artifactName as artifactName, tr.resolutionKey as resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.occurrence = :occurrence"
122 fun findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersionAndOccurrence(
123 @Param("blueprintName") blueprintName: String?,
124 @Param("blueprintVersion") blueprintVersion: String?,
125 @Param("occurrence") occurrence: Int
126 ): List<TemplateResolutionSelector>?
129 fun deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
131 resourceType: String,
132 blueprintName: String?,
133 blueprintVersion: String?,
134 artifactName: String,
139 fun deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
141 blueprintName: String?,
142 blueprintVersion: String?,
143 artifactName: String,