Expose completion future from WriteOperations
[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.util.concurrent.FluentFuture;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.common.api.TransactionDatastoreMismatchException;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16
17 /**
18  * Write-like operations supported by {@link WriteTransaction} and {@link ReadWriteTransaction}. This interface defines
19  * the operations without a tie-in with lifecycle management.
20  */
21 public interface WriteOperations {
22     /**
23      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that
24      * whole subtree will be replaced by the specified data.
25      *
26      * <p>
27      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
28      * put, consider using {@link #merge} instead.
29      *
30      * @param store the logical data store which should be modified
31      * @param path the data object path
32      * @param data the data object to be written to the specified path
33      * @throws IllegalStateException if the transaction has already been submitted
34      * @throws NullPointerException if any of the arguments is {@code null}
35      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
36      */
37     <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
38             @NonNull T data);
39
40     /**
41      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
42      * subtree will be replaced by the specified data. Unlike
43      * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
44      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
45      *
46      * <p>
47      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
48      * put, consider using {@link #merge} instead.
49      *
50      * <p>
51      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
52      *                 a previous transaction. It also has a significantly higher cost than
53      *                 {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when
54      *                 absolutely necessary.
55      *
56      * @param store the logical data store which should be modified
57      * @param path the data object path
58      * @param data the data object to be written to the specified path
59      * @throws IllegalStateException if the transaction has already been submitted
60      * @throws NullPointerException if any of the arguments is {@code null}
61      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
62      * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree
63      *             parent nodes which may have semantic meaning without assigning responsibility. The datastore handles
64      *             all the cases which do not attach semantics, such as {@code container}s without {@code presence},
65      *             {@code augmentation} and {@code list} encapsulation.
66      *             This method does not work in the general case, where there are:
67      *             <ul>
68      *               <li>{@code container} parents with {@code presence}, as these form a {@code mandatory} enforcement
69      *                   boundary. We cannot infer the mandatory nodes from {@code path} and hence we may end up wanting
70      *                   to create an invalid structure</li>
71      *               <li>{@code list} parents with {@code unique} encompassing other leaves than {@code key}. While we
72      *                   can re-create the key {@code leaf} items, we have no way of constructing of {@code unique}
73      *                   requirements.</li>
74      *             </ul>
75      *             Based on this analysis, all users of this method need to be migrated to have a proper lifecycle
76      *             relationship with entities responsible for managing such semantic items which are created by this
77      *             method.
78      */
79     @Deprecated(since = "11.0.3")
80     <T extends DataObject> void mergeParentStructurePut(@NonNull LogicalDatastoreType store,
81             @NonNull InstanceIdentifier<T> path, @NonNull T data);
82
83     /**
84      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
85      * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
86      *
87      * <p>
88      * If you require an explicit replace operation, use {@link #put} instead.
89      *
90      * @param store the logical data store which should be modified
91      * @param path the data object path
92      * @param data the data object to be merged to the specified path
93      * @throws IllegalStateException if the transaction has already been submitted
94      * @throws NullPointerException if any of the arguments is {@code null}
95      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
96      */
97     <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
98             @NonNull T data);
99
100     /**
101      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
102      * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike
103      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
104      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
105      *
106      * <p>
107      * If you require an explicit replace operation, use {@link #put} instead.
108      *
109      * <p>
110      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
111      *                 a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
112      *                 than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used
113      *                 when absolutely necessary.
114      *
115      * @param store the logical data store which should be modified
116      * @param path the data object path
117      * @param data the data object to be merged to the specified path
118      * @throws IllegalStateException if the transaction has already been submitted
119      * @throws NullPointerException if any of the arguments is {@code null}
120      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
121      * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree
122      *             parent nodes which may have semantic meaning without assigning responsibility. The datastore handles
123      *             all the cases which do not attach semantics, such as {@code container}s without {@code presence},
124      *             {@code augmentation} and {@code list} encapsulation.
125      *             This method does not work in the general case, where there are:
126      *             <ul>
127      *               <li>{@code container} parents with {@code presence}, as these form a {@code mandatory} enforcement
128      *                   boundary. We cannot infer the mandatory nodes from {@code path} and hence we may end up wanting
129      *                   to create an invalid structure</li>
130      *               <li>{@code list} parents with {@code unique} encompassing other leaves than {@code key}. While we
131      *                   can re-create the key {@code leaf} items, we have no way of constructing of {@code unique}
132      *                   requirements.</li>
133      *             </ul>
134      *             Based on this analysis, all users of this method need to be migrated to have a proper lifecycle
135      *             relationship with entities responsible for managing such semantic items which are created by this
136      *             method.
137      */
138     @Deprecated(since = "11.0.3")
139     <T extends DataObject> void mergeParentStructureMerge(@NonNull LogicalDatastoreType store,
140             @NonNull InstanceIdentifier<T> path, @NonNull T data);
141
142     /**
143      * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
144      *
145      * @param store Logical data store which should be modified
146      * @param path Data object path
147      * @throws IllegalStateException if the transaction was committed or canceled.
148      * @throws NullPointerException if any of the arguments is {@code null}
149      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
150      */
151     void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
152
153     /**
154      * Return a {@link FluentFuture} which completes.
155      *
156      * @return A future which completes when the requested operations complete.
157      */
158     @NonNull FluentFuture<?> completionFuture();
159 }