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