2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.javav2.api;
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;
21 * A transaction that provides mutation capabilities on a data tree.
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
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.
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.
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.
42 * Performing the following put operations:
45 * 1) container { list [ a ] }
46 * 2) container { list [ b ] }
48 * will result in the following data being present:
51 * container { list [ b ] }
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.
58 * Performing the following merge operations:
61 * 1) container { list [ a ] }
62 * 2) container { list [ b ] }
64 * will result in the following data being present:
67 * container { list [ a, b ] }
69 * This also means that storing the container will preserve any augmentations which have been attached to it.
71 * <h2>Delete operation</h2>
72 * Removes a piece of data from a specified path.
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.
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.
84 * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL, but only to be
88 public interface WriteTransaction extends AsyncWriteTransaction<InstanceIdentifier<?>, TreeNode>, Transaction {
94 @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
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.
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.
106 * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
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.
112 * the logical data store which should be modified
114 * the data object path
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
121 <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
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.
129 * For more information on usage and examples, please see the documentation
130 * in {@link AsyncWriteTransaction}.
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}
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.
143 * the logical data store which should be modified
145 * the data object path
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
155 <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
156 boolean createMissingParents);
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.
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.
169 * For more information on usage and examples, please see the documentation in
170 * {@link AsyncWriteTransaction}.
173 * If you require an explicit replace operation, use {@link #put} instead.
175 * the logical data store which should be modified
177 * the data object path
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
184 <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
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.
192 * For more information on usage and examples, please see the documentation
193 * in {@link AsyncWriteTransaction}.
196 * If you require an explicit replace operation, use {@link #put} instead.
199 * the logical data store which should be modified
201 * the data object path
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
211 <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
212 boolean createMissingParents);
215 * Flag value indicating that missing parents should be created.
217 boolean CREATE_MISSING_PARENTS = true;
220 * Flag value indicating that missing parents should cause an error.
222 boolean FAIL_ON_MISSING_PARENTS = false;