10e582ad3da2b0320cc282108c588c8b4ef5bec1
[mdsal.git] / binding2 / mdsal-binding2-api / src / main / java / org / opendaylight / mdsal / binding / javav2 / api / WriteTransaction.java
1 /*
2  * Copyright (c) 2017 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.javav2.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.FluentFuture;
12 import javax.annotation.CheckReturnValue;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
15 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
16 import org.opendaylight.mdsal.common.api.AsyncWriteTransaction;
17 import org.opendaylight.mdsal.common.api.CommitInfo;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19
20 /**
21  * A transaction that provides mutation capabilities on a data tree.
22  *
23  * <p>
24  * Initial state of write transaction is a stable snapshot of the current data tree. The state is captured when
25  * the transaction is created and its state and underlying data tree are not affected by other concurrently running
26  * transactions.
27  *
28  * <p>
29  * Write transactions are isolated from other concurrent write transactions. All writes are local to the transaction
30  * and represent only a proposal of state change for the data tree and it is not visible to any other concurrently
31  * running transaction.
32  *
33  * <p>
34  * Applications make changes to the local data tree in the transaction by via the <b>put</b>, <b>merge</b>,
35  * and <b>delete</b> operations.
36  *
37  * <h2>Put operation</h2>
38  * Stores a piece of data at a specified path. This acts as an add / replace operation, which is to say that whole
39  * subtree will be replaced by the specified data.
40  *
41  * <p>
42  * Performing the following put operations:
43  *
44  * <pre>
45  * 1) container { list [ a ] }
46  * 2) container { list [ b ] }
47  * </pre>
48  * will result in the following data being present:
49  *
50  * <pre>
51  * container { list [ b ] }
52  * </pre>
53  * <h2>Merge operation</h2>
54  * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
55  * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
56  *
57  * <p>
58  * Performing the following merge operations:
59  *
60  * <pre>
61  * 1) container { list [ a ] }
62  * 2) container { list [ b ] }
63  * </pre>
64  * will result in the following data being present:
65  *
66  * <pre>
67  * container { list [ a, b ] }
68  * </pre>
69  * This also means that storing the container will preserve any augmentations which have been attached to it.
70  *
71  * <h2>Delete operation</h2>
72  * Removes a piece of data from a specified path.
73  *
74  * <p>
75  * After applying changes to the local data tree, applications publish the changes proposed in the transaction
76  * by calling {@link #commit} on the transaction. This seals the transaction (preventing any further writes using this
77  * transaction) and commits it to be processed and applied to global conceptual data tree.
78  *
79  * <p>
80  * The transaction commit may fail due to a concurrent transaction modifying and committing data in an incompatible way.
81  * See {@link #commit} for more concrete commit failure examples.
82  *
83  * <p>
84  * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL, but only to be
85  * consumed by them.
86  */
87 @Beta
88 public interface WriteTransaction extends AsyncWriteTransaction<InstanceIdentifier<?>, TreeNode>, Transaction {
89     @Override
90     boolean cancel();
91
92     @Override
93     @CheckReturnValue
94     @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
95
96     /**
97      * Stores a piece of data at the specified path. This acts as an add / replace
98      * operation, which is to say that whole subtree will be replaced by the specified data.
99      *
100      * <p>
101      * This method does not automatically create missing parent nodes. It is equivalent to invoking
102      * {@link #put(LogicalDatastoreType, InstanceIdentifier, TreeNode, boolean)}
103      * with <code>createMissingParents</code> set to false.
104      *
105      * <p>
106      * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
107      * <p>
108      * If you need to make sure that a parent object exists but you do not want modify
109      * its pre-existing state by using put, consider using {@link #merge} instead.
110      *
111      * @param store
112      *            the logical data store which should be modified
113      * @param path
114      *            the data object path
115      * @param data
116      *            the data object to be written to the specified path
117      * @param <T> data tree type
118      * @throws IllegalStateException
119      *             if the transaction has already been submitted
120      */
121     <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
122
123     /**
124      * Stores a piece of data at the specified path. This acts as an add /
125      * replace operation, which is to say that whole subtree will be replaced by
126      * the specified data.
127      *
128      * <p>
129      * For more information on usage and examples, please see the documentation
130      * in {@link AsyncWriteTransaction}.
131      *
132      * <p>
133      * If you need to make sure that a parent object exists but you do not want
134      * modify its pre-existing state by using put, consider using {@link #merge}
135      * instead.
136      *
137      * <p>
138      * Note: Using <code>createMissingParents</code> with value true, may
139      * introduce garbage in data store, or recreate nodes, which were deleted by
140      * previous transaction.
141      *
142      * @param store
143      *            the logical data store which should be modified
144      * @param path
145      *            the data object path
146      * @param data
147      *            the data object to be written to the specified path
148      * @param createMissingParents
149      *            if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically
150      *            created using a merge operation.
151      * @param <T> data tree type
152      * @throws IllegalStateException
153      *             if the transaction has already been submitted
154      */
155     <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
156         boolean createMissingParents);
157
158     /**
159      * Merges a piece of data with the existing data at a specified path. Any pre-existing data
160      * which is not explicitly overwritten will be preserved. This means that if you store a container,
161      * its child lists will be merged.
162      *
163      * <p>
164      * This method does not automatically create missing parent nodes. It is equivalent to invoking
165      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, TreeNode, boolean)}
166      * with <code>createMissingParents</code> set to false.
167      *
168      * <p>
169      * For more information on usage and examples, please see the documentation in
170      * {@link AsyncWriteTransaction}.
171      *
172      *<p>
173      * If you require an explicit replace operation, use {@link #put} instead.
174      * @param store
175      *            the logical data store which should be modified
176      * @param path
177      *            the data object path
178      * @param data
179      *            the data object to be merged to the specified path
180      * @param <T> data tree type
181      * @throws IllegalStateException
182      *             if the transaction has already been submitted
183      */
184     <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
185
186     /**
187      * Merges a piece of data with the existing data at a specified path. Any
188      * pre-existing data which is not explicitly overwritten will be preserved.
189      * This means that if you store a container, its child lists will be merged.
190      *
191      * <p>
192      * For more information on usage and examples, please see the documentation
193      * in {@link AsyncWriteTransaction}.
194      *
195      * <p>
196      * If you require an explicit replace operation, use {@link #put} instead.
197      *
198      * @param store
199      *            the logical data store which should be modified
200      * @param path
201      *            the data object path
202      * @param data
203      *            the data object to be merged to the specified path
204      * @param createMissingParents
205      *            if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically created
206      *            using a merge operation.
207      * @param <T> data tree type
208      * @throws IllegalStateException
209      *             if the transaction has already been submitted
210      */
211     <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
212         boolean createMissingParents);
213
214     /**
215      * Flag value indicating that missing parents should be created.
216      */
217     boolean CREATE_MISSING_PARENTS = true;
218
219     /**
220      * Flag value indicating that missing parents should cause an error.
221      */
222     boolean FAIL_ON_MISSING_PARENTS = false;
223 }