8513bda88b03632b4e12abc850fd8e92c97daf73
[ccsdk/cds.git] /
1 /*
2  * Copyright (C) 2019 Bell Canada.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
17
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
23
24 @Repository
25 interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
26
27     @Query(
28         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",
29         nativeQuery = true
30     )
31     fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
32         @Param("key")key: String,
33         @Param("blueprintName")blueprintName: String,
34         @Param("blueprintVersion")blueprintVersion: String,
35         @Param("artifactName")artifactName: String,
36         @Param("name")name: String
37     ): ResourceResolution?
38
39     @Query(
40         value = "SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE resolution_key = :key AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName ",
41         nativeQuery = true
42     )
43     fun findMaxOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
44         @Param("key")key: String,
45         @Param("blueprintName")blueprintName: String,
46         @Param("blueprintVersion")blueprintVersion: String,
47         @Param("artifactName")artifactName: String
48     ): Int?
49
50     @Query(
51         value = "SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND resource_id = :resourceId AND resource_type = :resourceType ",
52         nativeQuery = true
53     )
54     fun findMaxOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
55         @Param("blueprintName")blueprintName: String,
56         @Param("blueprintVersion")blueprintVersion: String,
57         @Param("resourceId")resourceId: String,
58         @Param("resourceType")resourceType: String
59     ): Int?
60
61     fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
62         resolutionKey: String,
63         blueprintName: String,
64         blueprintVersion: String,
65         artifactPrefix: String
66     ): List<ResourceResolution>
67
68     fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
69         blueprintName: String,
70         blueprintVersion: String,
71         resourceId: String,
72         resourceType: String
73     ): List<ResourceResolution>
74
75     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
76         blueprintName: String?,
77         blueprintVersion: String?,
78         artifactName: String,
79         resolutionKey: String,
80         occurrence: Int
81     ): List<ResourceResolution>
82
83     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
84         blueprintName: String?,
85         blueprintVersion: String?,
86         artifactName: String,
87         resourceId: String,
88         resourceType: String,
89         occurrence: Int
90     ): List<ResourceResolution>
91
92     @Transactional
93     fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
94         blueprintName: String?,
95         blueprintVersion: String?,
96         artifactName: String,
97         resolutionKey: String
98     )
99 }