2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2025 OpenInfra Foundation Europe. All rights reserved.
4 * Modifications Copyright (C) 2021 Pantheon.tech
5 * Modifications Copyright (C) 2022 Bell Canada
6 * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.cps.spi;
26 import java.io.Serializable;
27 import java.util.Collection;
28 import java.util.List;
31 import org.onap.cps.api.model.DataNode;
32 import org.onap.cps.api.parameters.FetchDescendantsOption;
33 import org.onap.cps.api.parameters.PaginationOption;
36 Data Store interface that is responsible for handling yang data.
37 Please follow guidelines in https://gerrit.nordix.org/#/c/onap/ccsdk/features/+/6698/19/cps/interface-proposal/src/main/java/cps/javadoc/spi/DataStoreService.java
40 public interface CpsDataPersistenceService {
43 * Store multiple datanodes at once.
44 * @param dataspaceName dataspace name
45 * @param anchorName anchor name
46 * @param dataNodes data nodes
48 void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
52 * Add multiple children to a Fragment.
54 * @param dataspaceName dataspace name
55 * @param anchorName anchor name
56 * @param parentXpath parent xpath
57 * @param dataNodes collection of dataNodes
59 void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
62 * Adds list child elements to a Fragment.
64 * @param dataspaceName dataspace name
65 * @param anchorName anchor name
66 * @param parentNodeXpath parent node xpath
67 * @param listElementsCollection collection of data nodes representing list elements
69 void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
70 Collection<DataNode> listElementsCollection);
73 * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
74 * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
75 * is returned when a specific xpath is used (Example: /bookstore).
77 * @param dataspaceName dataspace name
78 * @param anchorName anchor name
79 * @param xpath one xpath
80 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
81 * (recursively) as well
82 * @return collection of data node object
84 Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
85 FetchDescendantsOption fetchDescendantsOption);
88 * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
90 * @param dataspaceName dataspace name
91 * @param anchorName anchor name
92 * @param xpaths collection of xpaths
93 * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
94 * (recursively) as well
95 * @return collection of data node object
97 Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
98 Collection<String> xpaths,
99 FetchDescendantsOption fetchDescendantsOption);
102 * Updates data leaves for multiple data nodes.
104 * @param dataspaceName dataspace name
105 * @param anchorName anchor name
106 * @param updatedLeavesPerXPath Map of xPaths to updated leaf nodes
108 void batchUpdateDataLeaves(String dataspaceName, String anchorName,
109 Map<String, Map<String, Serializable>> updatedLeavesPerXPath);
112 * Replaces multiple existing data nodes' content including descendants in a batch operation.
114 * @param dataspaceName dataspace name
115 * @param anchorName anchor name
116 * @param dataNodes data nodes
118 void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final Collection<DataNode> dataNodes);
121 * Replaces list content by removing all existing elements and inserting the given new elements
122 * under given parent, anchor and dataspace.
124 * @param dataspaceName dataspace name
125 * @param anchorName anchor name
126 * @param parentNodeXpath parent node xpath
127 * @param newListElements collection of data nodes representing the new list content
129 void replaceListContent(String dataspaceName, String anchorName,
130 String parentNodeXpath, Collection<DataNode> newListElements);
133 * Deletes any dataNode, yang container or yang list or yang list element.
135 * @param dataspaceName dataspace name
136 * @param anchorName anchor name
137 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
139 void deleteDataNode(String dataspaceName, String anchorName, String targetXpath);
142 * Deletes multiple dataNode, yang container or yang list or yang list element.
144 * @param dataspaceName dataspace name
145 * @param anchorName anchor name
146 * @param targetXpaths xpaths of nodes to delete
148 void deleteDataNodes(String dataspaceName, String anchorName, Collection<String> targetXpaths);
151 * Deletes all dataNodes in a given anchor.
153 * @param dataspaceName dataspace name
154 * @param anchorName anchor name
156 void deleteDataNodes(String dataspaceName, String anchorName);
159 * Deletes all dataNodes in multiple anchors.
161 * @param dataspaceName dataspace name
162 * @param anchorNames anchor names
164 void deleteDataNodes(String dataspaceName, Collection<String> anchorNames);
167 * Deletes a single existing list element or the whole list.
169 * @param dataspaceName dataspace name
170 * @param anchorName anchor name
171 * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
173 void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath);
176 * Get a datanode by cps path.
178 * @param dataspaceName dataspace name
179 * @param anchorName anchor name
180 * @param cpsPath cps path
181 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
182 * included in the output
183 * @return the data nodes found i.e. 0 or more data nodes
185 List<DataNode> queryDataNodes(String dataspaceName, String anchorName,
186 String cpsPath, FetchDescendantsOption fetchDescendantsOption);
189 * Get a datanode by cps path.
191 * @param dataspaceName dataspace name
192 * @param anchorName anchor name
193 * @param cpsPath cps path
194 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
195 * included in the output
196 * @param queryResultLimit limits the number of returned entities (if less than 1 returns all)
198 * @return the data nodes found i.e. 0 or more data nodes
200 List<DataNode> queryDataNodes(String dataspaceName,
202 String cpsPath, FetchDescendantsOption fetchDescendantsOption,
203 int queryResultLimit);
206 * Get data leaf for the given dataspace and anchor by cps path.
208 * @param dataspaceName dataspace name
209 * @param anchorName anchor name
210 * @param cpsPath cps path
211 * @param queryResultLimit limits the number of returned entities (if less than 1 returns all)
212 * @param targetClass class of the expected data type
213 * @return a collection of data objects of expected type
215 <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit,
216 Class<T> targetClass);
219 * Get a datanode by dataspace name and cps path across all anchors.
221 * @param dataspaceName dataspace name
222 * @param cpsPath cps path
223 * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be
224 * included in the output
225 * @param paginationOption pagination option
226 * @return the data nodes found i.e. 0 or more data nodes
228 List<DataNode> queryDataNodesAcrossAnchors(String dataspaceName,
229 String cpsPath, FetchDescendantsOption fetchDescendantsOption,
230 PaginationOption paginationOption);
233 * Starts a session which allows use of locks and batch interaction with the persistence service.
235 * @return Session ID string
237 String startSession();
242 * @param sessionId session ID
244 void closeSession(String sessionId);
248 * To release locks(s), the session holding the lock(s) must be closed.
250 * @param sessionID session ID
251 * @param dataspaceName dataspace name
252 * @param anchorName anchor name
253 * @param timeoutInMilliseconds lock attempt timeout in milliseconds
255 void lockAnchor(String sessionID, String dataspaceName, String anchorName, Long timeoutInMilliseconds);
258 * Query total anchors for dataspace name and cps path.
259 * @param dataspaceName datasoace name
260 * @param cpsPath cps path
261 * @return total anchors for dataspace name and cps path
263 Integer countAnchorsForDataspaceAndCpsPath(String dataspaceName, String cpsPath);