2 * Copyright (c) 2018 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.api;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 * Write-like operations supported by {@link WriteTransaction} and {@link ReadWriteTransaction}. This interface defines
18 * the operations without a tie-in with lifecycle management.
20 public interface WriteOperations {
22 * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that
23 * whole subtree will be replaced by the specified data.
26 * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
27 * put, consider using {@link #merge} instead.
29 * @param store the logical data store which should be modified
30 * @param path the data object path
31 * @param data the data object to be written to the specified path
32 * @throws IllegalStateException if the transaction has already been submitted
33 * @throws NullPointerException if any of the arguments is null
35 <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
39 * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
40 * subtree will be replaced by the specified data.
43 * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
44 * put, consider using {@link #merge} instead.
46 * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
47 * a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
48 * than {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used
49 * when absolutely necessary.
51 * @param store the logical data store which should be modified
52 * @param path the data object path
53 * @param data the data object to be written to the specified path
54 * @param createMissingParents if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically
55 * created using a merge operation. <b>WARNING:</b> using this option is not needed
56 * in most scenarios and has a significant performance cost and should be avoided
58 * @throws IllegalStateException if the transaction has already been submitted
59 * @throws NullPointerException if any of the arguments is null
60 * @deprecated Use {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} or
61 * {@link #mergeParentStructurePut(LogicalDatastoreType, InstanceIdentifier, DataObject)}
65 <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
66 @NonNull T data, boolean createMissingParents);
69 * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
70 * subtree will be replaced by the specified data. Unlike
71 * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
72 * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
75 * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
76 * put, consider using {@link #merge} instead.
79 * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
80 * a previous transaction. It also has a significantly higher cost than
81 * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when
82 * absolutely necessary.
84 * @param store the logical data store which should be modified
85 * @param path the data object path
86 * @param data the data object to be written to the specified path
87 * @throws IllegalStateException if the transaction has already been submitted
88 * @throws NullPointerException if any of the arguments is null
90 // FIXME: 4.0.0: make this method non-default
91 // TODO: can we come up with a better name?
93 default <T extends DataObject> void mergeParentStructurePut(@NonNull final LogicalDatastoreType store,
94 @NonNull final InstanceIdentifier<T> path, @NonNull final T data) {
95 put(store, path, data, CREATE_MISSING_PARENTS);
99 * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
100 * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
103 * If you require an explicit replace operation, use {@link #put} instead.
105 * @param store the logical data store which should be modified
106 * @param path the data object path
107 * @param data the data object to be merged to the specified path
108 * @throws IllegalStateException if the transaction has already been submitted
109 * @throws NullPointerException if any of the arguments is null
111 <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
115 * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
116 * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
119 * If you require an explicit replace operation, use {@link #put} instead.
121 * @param store the logical data store which should be modified
122 * @param path the data object path
123 * @param data the data object to be merged to the specified path
124 * @param createMissingParents if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically
125 * created using a merge operation. <b>WARNING:</b> using this option is not needed
126 * in most scenarios and has a significant performance cost and should be avoided
128 * @throws IllegalStateException if the transaction has already been submitted
129 * @throws NullPointerException if any of the arguments is null
130 * @deprecated Use {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)} or
131 * {@link #mergeParentStructureMerge(LogicalDatastoreType, InstanceIdentifier, DataObject)}
135 <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
136 @NonNull T data, boolean createMissingParents);
139 * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
140 * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike
141 * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
142 * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
145 * If you require an explicit replace operation, use {@link #put} instead.
148 * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
149 * a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
150 * than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used
151 * when absolutely necessary.
153 * @param store the logical data store which should be modified
154 * @param path the data object path
155 * @param data the data object to be merged to the specified path
156 * @throws IllegalStateException if the transaction has already been submitted
157 * @throws NullPointerException if any of the arguments is null
159 // FIXME: 4.0.0: make this method non-default
160 // TODO: can we come up with a better name?
162 default <T extends DataObject> void mergeParentStructureMerge(@NonNull final LogicalDatastoreType store,
163 @NonNull final InstanceIdentifier<T> path, @NonNull final T data) {
164 merge(store, path, data, CREATE_MISSING_PARENTS);
168 * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
170 * @param store Logical data store which should be modified
171 * @param path Data object path
172 * @throws IllegalStateException if the transaction was committed or canceled.
174 void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
177 * Flag value indicating that missing parents should be created.
180 * <b>WARNING:</b> Using this flag may introduce garbage in data store, or recreate nodes, which were deleted by
181 * a previous transaction. It is not necessary in most scenarios and also has a significantly higher
182 * cost than {@link #FAIL_ON_MISSING_PARENTS} and should only be used when absolutely necessary.
184 * @deprecated To be removed with {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}
185 * and {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}.
188 boolean CREATE_MISSING_PARENTS = true;
191 * Flag value indicating that missing parents should cause an error.
193 * @deprecated To be removed with {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}
194 * and {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject, boolean)}.
197 boolean FAIL_ON_MISSING_PARENTS = false;