2 * Copyright (c) 2014 Cisco Systems, Inc. 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.api;
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;
20 * A transaction that provides mutation capabilities on a data tree.
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
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.
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.
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.
41 * Performing the following put operations:
44 * 1) container { list [ a ] }
45 * 2) container { list [ b ] }
47 * will result in the following data being present:
50 * container { list [ b ] }
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.
57 * Performing the following merge operations:
60 * 1) container { list [ a ] }
61 * 2) container { list [ b ] }
63 * will result in the following data being present:
66 * container { list [ a, b ] }
68 * This also means that storing the container will preserve any augmentations which have been attached to it.
70 * <h2>Delete operation</h2>
71 * Removes a piece of data from a specified path.
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.
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.
83 * <b>Implementation Note:</b> This interface is not intended to be implemented by users of MD-SAL, but only to be
86 public interface WriteTransaction extends Transaction, AsyncWriteTransaction<InstanceIdentifier<?>, DataObject> {
92 @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
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.
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.
104 * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
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.
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
115 <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
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.
123 * For more information on usage and examples, please see the documentation
124 * in {@link AsyncWriteTransaction}.
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}
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.
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
144 <T extends DataObject> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
145 boolean createMissingParents);
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.
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.
157 * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
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
167 <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
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.
174 * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
177 * If you require an explicit replace operation, use {@link #put} instead.
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
187 <T extends DataObject> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
188 boolean createMissingParents);
191 void delete(LogicalDatastoreType store, InstanceIdentifier<?> path);
194 * Flag value indicating that missing parents should be created.
196 boolean CREATE_MISSING_PARENTS = true;
199 * Flag value indicating that missing parents should cause an error.
201 boolean FAIL_ON_MISSING_PARENTS = false;