2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Pantheon.tech
4 * Modifications Copyright (C) 2021-2023 Nordix Foundation
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.spi.repository;
23 import java.util.Collection;
24 import java.util.List;
26 import org.onap.cps.spi.entities.YangResourceEntity;
27 import org.onap.cps.spi.entities.YangResourceModuleReference;
28 import org.springframework.data.jpa.repository.JpaRepository;
29 import org.springframework.data.jpa.repository.Modifying;
30 import org.springframework.data.jpa.repository.Query;
31 import org.springframework.data.repository.query.Param;
32 import org.springframework.stereotype.Repository;
35 public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Integer>,
36 YangResourceNativeRepository, SchemaSetYangResourceRepository {
38 List<YangResourceEntity> findAllByChecksumIn(String[] checksums);
40 default List<YangResourceEntity> findAllByChecksumIn(final Collection<String> checksums) {
41 return findAllByChecksumIn(checksums.toArray(new String[0]));
46 yang_resource.module_name AS module_name,
47 yang_resource.revision AS revision
50 JOIN schema_set ON schema_set.dataspace_id = dataspace.id
51 JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
52 JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
54 dataspace.name = :dataspaceName
55 """, nativeQuery = true)
56 Set<YangResourceModuleReference> findAllModuleReferencesByDataspace(@Param("dataspaceName") String dataspaceName);
60 yang_resource.module_name AS module_name,
61 yang_resource.revision AS revision
64 JOIN anchor ON anchor.dataspace_id = dataspace.id
65 JOIN schema_set ON schema_set.id = anchor.schema_set_id
66 JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
67 JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
69 dataspace.name = :dataspaceName
70 AND anchor.name = :anchorName
71 """, nativeQuery = true)
72 Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndAnchor(
73 @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
80 JOIN anchor ON anchor.dataspace_id = dataspace.id
81 JOIN schema_set ON schema_set.id = anchor.schema_set_id
82 JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
83 JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
85 dataspace.name = :dataspaceName
86 AND anchor.name = :anchorName
87 """, nativeQuery = true)
88 Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchor(
89 @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
96 JOIN schema_set ON schema_set.dataspace_id = dataspace.id
97 JOIN schema_set_yang_resources ON schema_set_yang_resources.schema_set_id = schema_set.id
98 JOIN yang_resource ON yang_resource.id = schema_set_yang_resources.yang_resource_id
100 dataspace.name = :dataspaceName
101 AND yang_resource.module_name = ANY ( :moduleNames )
102 """, nativeQuery = true)
103 Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndModuleNames(
104 @Param("dataspaceName") String dataspaceName, @Param("moduleNames") String[] moduleNames);
106 default Set<YangResourceModuleReference> findAllModuleReferencesByDataspaceAndModuleNames(
107 final String dataspaceName, final Collection<String> moduleNames) {
108 return findAllModuleReferencesByDataspaceAndModuleNames(dataspaceName, moduleNames.toArray(new String[0]));
112 @Query(value = "DELETE FROM yang_resource yr WHERE NOT EXISTS "
113 + "(SELECT 1 FROM schema_set_yang_resources ssyr WHERE ssyr.yang_resource_id = yr.id)", nativeQuery = true)
114 void deleteOrphans();