6e0ed3a4bfec79cd14de841c662c95fdf55e3e52
[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     fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
40         resolutionKey: String,
41         blueprintName: String,
42         blueprintVersion: String,
43         artifactPrefix: String
44     ): List<ResourceResolution>
45
46     fun findByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
47         blueprintName: String,
48         blueprintVersion: String,
49         resourceId: String,
50         resourceType: String
51     ): List<ResourceResolution>
52
53     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
54         blueprintName: String?,
55         blueprintVersion: String?,
56         artifactName: String,
57         resolutionKey: String,
58         occurrence: Int
59     ): List<ResourceResolution>
60
61     fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
62         blueprintName: String?,
63         blueprintVersion: String?,
64         artifactName: String,
65         resourceId: String,
66         resourceType: String,
67         occurrence: Int
68     ): List<ResourceResolution>
69
70     @Transactional
71     fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
72         blueprintName: String?,
73         blueprintVersion: String?,
74         artifactName: String,
75         resolutionKey: String
76     )
77 }