[CPS] RI: Code Refactoring
[cps.git] / cps-service / src / main / java / org / onap / cps / spi / CpsDataPersistenceService.java
index 3e0b447..d28a333 100644 (file)
@@ -3,7 +3,7 @@
  *  Copyright (C) 2020-2023 Nordix Foundation.
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2022 Bell Canada
- *  Modifications Copyright (C) 2022 TechMahindra Ltd.
+ *  Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,18 +36,6 @@ import org.onap.cps.spi.model.DataNode;
  */
 public interface CpsDataPersistenceService {
 
-
-    /**
-     * Store a datanode.
-     *
-     * @param dataspaceName dataspace name
-     * @param anchorName    anchor name
-     * @param dataNode      data node
-     * @deprecated Please use {@link #storeDataNodes(String, String, Collection)} as it supports multiple data nodes.
-     */
-    @Deprecated
-    void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
-
     /**
      * Store multiple datanodes at once.
      * @param dataspaceName dataspace name
@@ -99,30 +87,33 @@ public interface CpsDataPersistenceService {
             Collection<Collection<DataNode>> newLists);
 
     /**
-     * Retrieves datanode by XPath for given dataspace and anchor.
+     * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
+     * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
+     * is returned when a specific xpath is used (Example: /bookstore).
      *
      * @param dataspaceName          dataspace name
      * @param anchorName             anchor name
-     * @param xpath                  xpath
+     * @param xpath                  one xpath
      * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
      *                               (recursively) as well
-     * @return data node object
+     * @return collection of data node object
      */
-    DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
-        FetchDescendantsOption fetchDescendantsOption);
+    Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
+                                      FetchDescendantsOption fetchDescendantsOption);
 
     /**
-     * Retrieves datanode by XPath for given dataspace and anchor.
+     * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
      *
-     * @param dataspaceName          dataspace name
-     * @param anchorName             anchor name
-     * @param xpaths                 collection of xpaths
-     * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
-     *                               (recursively) as well
-     * @return data node object
+     * @param dataspaceName           dataspace name
+     * @param anchorName              anchor name
+     * @param xpaths                  collection of xpaths
+     * @param fetchDescendantsOption  defines the scope of data to fetch: either single node or all the descendant nodes
+     *                                (recursively) as well
+     * @return collection of data node object
      */
-    Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
-                         FetchDescendantsOption fetchDescendantsOption);
+    Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
+                                                       Collection<String> xpaths,
+                                                       FetchDescendantsOption fetchDescendantsOption);
 
     /**
      * Updates leaves for existing data node.
@@ -134,15 +125,6 @@ public interface CpsDataPersistenceService {
      */
     void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
 
-    /**
-     * Replaces an existing data node's content including descendants.
-     *
-     * @param dataspaceName dataspace name
-     * @param anchorName    anchor name
-     * @param dataNode      data node
-     */
-    void updateDataNodeAndDescendants(String dataspaceName, String anchorName, DataNode dataNode);
-
     /**
      * Replaces multiple existing data nodes' content including descendants in a batch operation.
      *
@@ -150,7 +132,7 @@ public interface CpsDataPersistenceService {
      * @param anchorName    anchor name
      * @param dataNodes     data nodes
      */
-    void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final List<DataNode> dataNodes);
+    void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
 
     /**
      * Replaces list content by removing all existing elements and inserting the given new elements
@@ -190,6 +172,14 @@ public interface CpsDataPersistenceService {
      */
     void deleteDataNodes(String dataspaceName, String anchorName);
 
+    /**
+     * Deletes all dataNodes in multiple anchors.
+     *
+     * @param dataspaceName   dataspace name
+     * @param anchorNames     anchor names
+     */
+    void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
+
     /**
      * Deletes a single existing list element or the whole list.
      *
@@ -212,6 +202,19 @@ public interface CpsDataPersistenceService {
     List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
                                   String cpsPath, FetchDescendantsOption fetchDescendantsOption);
 
+    /**
+     * Get a datanode by dataspace name and cps path across all anchors.
+     *
+     * @param dataspaceName          dataspace name
+     * @param cpsPath                cps path
+     * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
+     *                               included in the output
+     * @return the data nodes found i.e. 0 or more data nodes
+     */
+    List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
+                                  String cpsPath, FetchDescendantsOption fetchDescendantsOption);
+
+
     /**
      * Starts a session which allows use of locks and batch interaction with the persistence service.
      *