Add NotificationService.registerListener()
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / WriteOperations.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.api;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
15
16 /**
17  * Write-like operations supported by {@link WriteTransaction} and {@link ReadWriteTransaction}. This interface defines
18  * the operations without a tie-in with lifecycle management.
19  */
20 public interface WriteOperations {
21     /**
22      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that
23      * whole subtree will be replaced by the specified data.
24      *
25      * <p>
26      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
27      * put, consider using {@link #merge} instead.
28      *
29      * @param store the logical data store which should be modified
30      * @param path the data object path
31      * @param data the data object to be written to the specified path
32      * @throws IllegalStateException if the transaction has already been submitted
33      * @throws NullPointerException if any of the arguments is null
34      */
35     <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
36             @NonNull T data);
37
38     /**
39      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
40      * subtree will be replaced by the specified data. Unlike
41      * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
42      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
43      *
44      * <p>
45      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
46      * put, consider using {@link #merge} instead.
47      *
48      * <p>
49      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
50      *                 a previous transaction. It also has a significantly higher cost than
51      *                 {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when
52      *                 absolutely necessary.
53      *
54      * @param store the logical data store which should be modified
55      * @param path the data object path
56      * @param data the data object to be written to the specified path
57      * @throws IllegalStateException if the transaction has already been submitted
58      * @throws NullPointerException if any of the arguments is null
59      */
60     // TODO: can we come up with a better name?
61     @Beta
62     <T extends DataObject> void mergeParentStructurePut(@NonNull LogicalDatastoreType store,
63             @NonNull InstanceIdentifier<T> path, @NonNull T data);
64
65     /**
66      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
67      * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
68      *
69      * <p>
70      * If you require an explicit replace operation, use {@link #put} instead.
71      *
72      * @param store the logical data store which should be modified
73      * @param path the data object path
74      * @param data the data object to be merged to the specified path
75      * @throws IllegalStateException if the transaction has already been submitted
76      * @throws NullPointerException if any of the arguments is null
77      */
78     <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
79             @NonNull T data);
80
81     /**
82      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
83      * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike
84      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
85      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
86      *
87      * <p>
88      * If you require an explicit replace operation, use {@link #put} instead.
89      *
90      * <p>
91      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
92      *                 a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
93      *                 than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used
94      *                 when absolutely necessary.
95      *
96      * @param store the logical data store which should be modified
97      * @param path the data object path
98      * @param data the data object to be merged to the specified path
99      * @throws IllegalStateException if the transaction has already been submitted
100      * @throws NullPointerException if any of the arguments is null
101      */
102     // TODO: can we come up with a better name?
103     @Beta
104     <T extends DataObject> void mergeParentStructureMerge(@NonNull LogicalDatastoreType store,
105             @NonNull InstanceIdentifier<T> path, @NonNull T data);
106
107     /**
108      * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
109      *
110      * @param store Logical data store which should be modified
111      * @param path Data object path
112      * @throws IllegalStateException if the transaction was committed or canceled.
113      */
114     void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
115 }