X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ri%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fspi%2Frepository%2FFragmentRepository.java;h=a40168a9d65e0e80387c88f1a413f4cc75e3c82f;hb=760e597acc7854a736363a0136343b5a77462cfb;hp=bf551723f850f0219a08a325b44a55a2d01f8091;hpb=55c4135bff02800659ddc4d2de15222ba229ac51;p=cps.git diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java index bf551723f..a40168a9d 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java @@ -22,6 +22,7 @@ package org.onap.cps.spi.repository; import java.util.Collection; +import java.util.List; import java.util.Optional; import javax.validation.constraints.NotNull; import org.checkerframework.checker.nullness.qual.NonNull; @@ -51,4 +52,12 @@ public interface FragmentRepository extends JpaRepository @Query("DELETE FROM FragmentEntity fe WHERE fe.anchor IN (:anchors)") void deleteByAnchorIn(@NotNull @Param("anchors") Collection anchorEntities); + @Query(value = + "SELECT * FROM FRAGMENT WHERE (anchor_id = :anchor) AND (xpath = (:xpath) OR xpath LIKE " + + "CONCAT(:xpath,'\\[@%]')) AND attributes @> jsonb_build_object(:leafName , :leafValue)", + nativeQuery = true) + // Above query will match an xpath with or without the index for a list [@key=value] + // and match anchor id, leaf name and leaf value + List getByAnchorAndXpathAndLeafAttributes(@Param("anchor") int anchorId, @Param("xpath") + String xpathPrefix, @Param("leafName") String leafName, @Param("leafValue") Object leafValue); } \ No newline at end of file