bd695d365961d06954186b51be07944bc519c3ee
[mdsal.git] / binding / mdsal-binding-api / src / main / java / org / opendaylight / mdsal / binding / api / WriteOperations.java
1 /*
2  * Copyright (c) 2018 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.api;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
12 import org.opendaylight.mdsal.common.api.TransactionDatastoreMismatchException;
13 import org.opendaylight.yangtools.yang.binding.DataObject;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
15
16 /**
17  * Write-like operations supported by {@link WriteTransaction} and {@link ReadWriteTransaction}. This interface defines
18  * the operations without a tie-in with lifecycle management.
19  */
20 public interface WriteOperations {
21     /**
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.
24      *
25      * <p>
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.
28      *
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 {@code null}
34      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
35      */
36     <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
37             @NonNull T data);
38
39     /**
40      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
41      * subtree will be replaced by the specified data. Unlike
42      * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
43      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
44      *
45      * <p>
46      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
47      * put, consider using {@link #merge} instead.
48      *
49      * <p>
50      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
51      *                 a previous transaction. It also has a significantly higher cost than
52      *                 {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when
53      *                 absolutely necessary.
54      *
55      * @param store the logical data store which should be modified
56      * @param path the data object path
57      * @param data the data object to be written to the specified path
58      * @throws IllegalStateException if the transaction has already been submitted
59      * @throws NullPointerException if any of the arguments is {@code null}
60      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
61      * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree
62      *             parent nodes which may have semantic meaning without assigning responsibility. The datastore handles
63      *             all the cases which do not attach semantics, such as {@code container}s without {@code presence},
64      *             {@code augmentation} and {@code list} encapsulation.
65      *             This method does not work in the general case, where there are:
66      *             <ul>
67      *               <li>{@code container} parents with {@code presence}, as these form a {@code mandatory} enforcement
68      *                   boundary. We cannot infer the mandatory nodes from {@code path} and hence we may end up wanting
69      *                   to create an invalid structure</li>
70      *               <li>{@code list} parents with {@code unique} encompassing other leaves than {@code key}. While we
71      *                   can re-create the key {@code leaf} items, we have no way of constructing of {@code unique}
72      *                   requirements.</li>
73      *             </ul>
74      *             Based on this analysis, all users of this method need to be migrated to have a proper lifecycle
75      *             relationship with entities responsible for managing such semantic items which are created by this
76      *             method.
77      */
78     @Deprecated(since = "11.0.3")
79     <T extends DataObject> void mergeParentStructurePut(@NonNull LogicalDatastoreType store,
80             @NonNull InstanceIdentifier<T> path, @NonNull T data);
81
82     /**
83      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
84      * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
85      *
86      * <p>
87      * If you require an explicit replace operation, use {@link #put} instead.
88      *
89      * @param store the logical data store which should be modified
90      * @param path the data object path
91      * @param data the data object to be merged to the specified path
92      * @throws IllegalStateException if the transaction has already been submitted
93      * @throws NullPointerException if any of the arguments is {@code null}
94      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
95      */
96     <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
97             @NonNull T data);
98
99     /**
100      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
101      * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike
102      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
103      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
104      *
105      * <p>
106      * If you require an explicit replace operation, use {@link #put} instead.
107      *
108      * <p>
109      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
110      *                 a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
111      *                 than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used
112      *                 when absolutely necessary.
113      *
114      * @param store the logical data store which should be modified
115      * @param path the data object path
116      * @param data the data object to be merged to the specified path
117      * @throws IllegalStateException if the transaction has already been submitted
118      * @throws NullPointerException if any of the arguments is {@code null}
119      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
120      * @deprecated Use of this method is a manifestation of bad lifecycle management: it attempts to create data tree
121      *             parent nodes which may have semantic meaning without assigning responsibility. The datastore handles
122      *             all the cases which do not attach semantics, such as {@code container}s without {@code presence},
123      *             {@code augmentation} and {@code list} encapsulation.
124      *             This method does not work in the general case, where there are:
125      *             <ul>
126      *               <li>{@code container} parents with {@code presence}, as these form a {@code mandatory} enforcement
127      *                   boundary. We cannot infer the mandatory nodes from {@code path} and hence we may end up wanting
128      *                   to create an invalid structure</li>
129      *               <li>{@code list} parents with {@code unique} encompassing other leaves than {@code key}. While we
130      *                   can re-create the key {@code leaf} items, we have no way of constructing of {@code unique}
131      *                   requirements.</li>
132      *             </ul>
133      *             Based on this analysis, all users of this method need to be migrated to have a proper lifecycle
134      *             relationship with entities responsible for managing such semantic items which are created by this
135      *             method.
136      */
137     @Deprecated(since = "11.0.3")
138     <T extends DataObject> void mergeParentStructureMerge(@NonNull LogicalDatastoreType store,
139             @NonNull InstanceIdentifier<T> path, @NonNull T data);
140
141     /**
142      * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
143      *
144      * @param store Logical data store which should be modified
145      * @param path Data object path
146      * @throws IllegalStateException if the transaction was committed or canceled.
147      * @throws NullPointerException if any of the arguments is {@code null}
148      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
149      */
150     void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
151 }