Remove 32K limit from queries with collection parameters
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / repository / SchemaSetRepository.java
1 /*
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
10  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.spi.repository;
23
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;
35
36 @Repository
37 public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
38
39     Optional<SchemaSetEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String schemaSetName);
40
41     /**
42      * Gets schema sets by dataspace.
43      * @param dataspaceEntity dataspace entity
44      * @return list of schema set entity
45      */
46     List<SchemaSetEntity> findByDataspace(DataspaceEntity dataspaceEntity);
47
48     Integer countByDataspace(DataspaceEntity dataspaceEntity);
49
50     /**
51      * Gets a schema set by dataspace and schema set name.
52      *
53      * @param dataspaceEntity dataspace entity
54      * @param schemaSetName   schema set name
55      * @return schema set entity
56      * @throws SchemaSetNotFoundException if SchemaSet not found
57      */
58     default SchemaSetEntity getByDataspaceAndName(final DataspaceEntity dataspaceEntity, final String schemaSetName) {
59         return findByDataspaceAndName(dataspaceEntity, schemaSetName)
60             .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
61     }
62
63     @Modifying
64     @Query(value = "DELETE FROM schema_set WHERE dataspace_id = :dataspaceId AND name = ANY (:schemaSetNames)",
65         nativeQuery = true)
66     void deleteByDataspaceIdAndNameIn(@Param("dataspaceId") final int dataspaceId,
67                                       @Param("schemaSetNames") final String[] schemaSetNames);
68
69     /**
70      * Delete multiple schema sets in a given dataspace.
71      * @param dataspaceEntity dataspace entity
72      * @param schemaSetNames  schema set names
73      */
74     default void deleteByDataspaceAndNameIn(final DataspaceEntity dataspaceEntity,
75                                             final Collection<String> schemaSetNames) {
76         deleteByDataspaceIdAndNameIn(dataspaceEntity.getId(), schemaSetNames.toArray(new String[0]));
77     }
78
79 }