2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Pantheon.tech
4 * Modifications Copyright (C) 2022 TechMahindra Ltd.
5 * Modifications Copyright (C) 2023 Nordix Foundation
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.spi.repository;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.Optional;
27 import org.onap.cps.spi.entities.DataspaceEntity;
28 import org.onap.cps.spi.entities.SchemaSetEntity;
29 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
30 import org.springframework.data.jpa.repository.JpaRepository;
31 import org.springframework.data.jpa.repository.Modifying;
32 import org.springframework.data.jpa.repository.Query;
33 import org.springframework.data.repository.query.Param;
34 import org.springframework.stereotype.Repository;
37 public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
39 Optional<SchemaSetEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String schemaSetName);
42 * Gets schema sets by dataspace.
43 * @param dataspaceEntity dataspace entity
44 * @return list of schema set entity
46 List<SchemaSetEntity> findByDataspace(DataspaceEntity dataspaceEntity);
48 Integer countByDataspace(DataspaceEntity dataspaceEntity);
51 * Gets a schema set by dataspace and schema set name.
53 * @param dataspaceEntity dataspace entity
54 * @param schemaSetName schema set name
55 * @return schema set entity
56 * @throws SchemaSetNotFoundException if SchemaSet not found
58 default SchemaSetEntity getByDataspaceAndName(final DataspaceEntity dataspaceEntity, final String schemaSetName) {
59 return findByDataspaceAndName(dataspaceEntity, schemaSetName)
60 .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
64 @Query(value = "DELETE FROM schema_set WHERE dataspace_id = :dataspaceId AND name = ANY (:schemaSetNames)",
66 void deleteByDataspaceIdAndNameIn(@Param("dataspaceId") final int dataspaceId,
67 @Param("schemaSetNames") final String[] schemaSetNames);
70 * Delete multiple schema sets in a given dataspace.
71 * @param dataspaceEntity dataspace entity
72 * @param schemaSetNames schema set names
74 default void deleteByDataspaceAndNameIn(final DataspaceEntity dataspaceEntity,
75 final Collection<String> schemaSetNames) {
76 deleteByDataspaceIdAndNameIn(dataspaceEntity.getId(), schemaSetNames.toArray(new String[0]));