Persistence layer - Query Datanodes using cpsPath that contains contains a leaf name...
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / repository / FragmentRepository.java
index bf55172..a40168a 100755 (executable)
@@ -22,6 +22,7 @@
 package org.onap.cps.spi.repository;\r
 \r
 import java.util.Collection;\r
+import java.util.List;\r
 import java.util.Optional;\r
 import javax.validation.constraints.NotNull;\r
 import org.checkerframework.checker.nullness.qual.NonNull;\r
@@ -51,4 +52,12 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>
     @Query("DELETE FROM FragmentEntity fe WHERE fe.anchor IN (:anchors)")\r
     void deleteByAnchorIn(@NotNull @Param("anchors") Collection<AnchorEntity> anchorEntities);\r
 \r
+    @Query(value =\r
+        "SELECT * FROM FRAGMENT WHERE (anchor_id = :anchor) AND (xpath = (:xpath) OR xpath LIKE "\r
+            + "CONCAT(:xpath,'\\[@%]')) AND attributes @> jsonb_build_object(:leafName , :leafValue)",\r
+                nativeQuery = true)\r
+    // Above query will match an xpath with or without the index for a list [@key=value]\r
+    // and match anchor id, leaf name and leaf value\r
+    List<FragmentEntity> getByAnchorAndXpathAndLeafAttributes(@Param("anchor") int anchorId, @Param("xpath")\r
+        String xpathPrefix, @Param("leafName") String leafName, @Param("leafValue") Object leafValue);\r
 }
\ No newline at end of file