2 * ============LICENSE_START=======================================================
\r
3 * Copyright (C) 2020 Nordix Foundation. All rights reserved.
\r
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
\r
5 * ================================================================================
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
18 * SPDX-License-Identifier: Apache-2.0
\r
19 * ============LICENSE_END=========================================================
\r
22 package org.onap.cps.spi.repository;
\r
24 import java.util.Collection;
\r
25 import java.util.List;
\r
26 import java.util.Optional;
\r
27 import javax.validation.constraints.NotNull;
\r
28 import org.checkerframework.checker.nullness.qual.NonNull;
\r
29 import org.onap.cps.spi.entities.AnchorEntity;
\r
30 import org.onap.cps.spi.entities.DataspaceEntity;
\r
31 import org.onap.cps.spi.entities.FragmentEntity;
\r
32 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
\r
33 import org.springframework.data.jpa.repository.JpaRepository;
\r
34 import org.springframework.data.jpa.repository.Modifying;
\r
35 import org.springframework.data.jpa.repository.Query;
\r
36 import org.springframework.data.repository.query.Param;
\r
37 import org.springframework.stereotype.Repository;
\r
40 public interface FragmentRepository extends JpaRepository<FragmentEntity, Long> {
\r
42 Optional<FragmentEntity> findByDataspaceAndAnchorAndXpath(@NonNull DataspaceEntity dataspaceEntity,
\r
43 @NonNull AnchorEntity anchorEntity, @NonNull String xpath);
\r
45 default FragmentEntity getByDataspaceAndAnchorAndXpath(@NonNull DataspaceEntity dataspaceEntity,
\r
46 @NonNull AnchorEntity anchorEntity, @NonNull String xpath) {
\r
47 return findByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, xpath)
\r
48 .orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName(), xpath));
\r
52 @Query("DELETE FROM FragmentEntity fe WHERE fe.anchor IN (:anchors)")
\r
53 void deleteByAnchorIn(@NotNull @Param("anchors") Collection<AnchorEntity> anchorEntities);
\r
56 "SELECT * FROM FRAGMENT WHERE (anchor_id = :anchor) AND (xpath = (:xpath) OR xpath LIKE "
\r
57 + "CONCAT(:xpath,'\\[@%]')) AND attributes @> jsonb_build_object(:leafName , :leafValue)",
\r
59 // Above query will match an xpath with or without the index for a list [@key=value]
\r
60 // and match anchor id, leaf name and leaf value
\r
61 List<FragmentEntity> getByAnchorAndXpathAndLeafAttributes(@Param("anchor") int anchorId, @Param("xpath")
\r
62 String xpathPrefix, @Param("leafName") String leafName, @Param("leafValue") Object leafValue);
\r