2dc6a49e31538720742ad0dd2b4fa2b714969b84
[mdsal.git] / binding2 / mdsal-binding2-api / src / main / java / org / opendaylight / mdsal / binding / javav2 / api / WriteTransaction.java
1 /*
2  * Copyright (c) 2017 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
9 package org.opendaylight.mdsal.binding.javav2.api;
10
11 import com.google.common.annotations.Beta;
12 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
13 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
14 import org.opendaylight.mdsal.common.api.AsyncWriteTransaction;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16
17 /**
18  * A transaction that provides mutation capabilities on a data tree.
19  *
20  * <p>
21  * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
22  */
23 @Beta
24 public interface WriteTransaction extends AsyncWriteTransaction<InstanceIdentifier<?>, TreeNode> {
25
26     /**
27      * Stores a piece of data at the specified path. This acts as an add / replace
28      * operation, which is to say that whole subtree will be replaced by the specified data.
29      *
30      * <p>
31      * This method does not automatically create missing parent nodes. It is equivalent to invoking
32      * {@link #put(LogicalDatastoreType, InstanceIdentifier, TreeNode, boolean)}
33      * with <code>createMissingParents</code> set to false.
34      *
35      * <p>
36      * For more information on usage and examples, please see the documentation in {@link AsyncWriteTransaction}.
37      * <p>
38      * If you need to make sure that a parent object exists but you do not want modify
39      * its pre-existing state by using put, consider using {@link #merge} instead.
40      *
41      * @param store
42      *            the logical data store which should be modified
43      * @param path
44      *            the data object path
45      * @param data
46      *            the data object to be written to the specified path
47      * @param <T> data tree type
48      * @throws IllegalStateException
49      *             if the transaction has already been submitted
50      */
51     <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
52
53     /**
54      * Stores a piece of data at the specified path. This acts as an add /
55      * replace operation, which is to say that whole subtree will be replaced by
56      * the specified data.
57      *
58      * <p>
59      * For more information on usage and examples, please see the documentation
60      * in {@link AsyncWriteTransaction}.
61      *
62      * <p>
63      * If you need to make sure that a parent object exists but you do not want
64      * modify its pre-existing state by using put, consider using {@link #merge}
65      * instead.
66      *
67      * <p>
68      * Note: Using <code>createMissingParents</code> with value true, may
69      * introduce garbage in data store, or recreate nodes, which were deleted by
70      * previous transaction.
71      *
72      * @param store
73      *            the logical data store which should be modified
74      * @param path
75      *            the data object path
76      * @param data
77      *            the data object to be written to the specified path
78      * @param createMissingParents
79      *            if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically
80      *            created using a merge operation.
81      * @param <T> data tree type
82      * @throws IllegalStateException
83      *             if the transaction has already been submitted
84      */
85     <T extends TreeNode> void put(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
86         boolean createMissingParents);
87
88     /**
89      * Merges a piece of data with the existing data at a specified path. Any pre-existing data
90      * which is not explicitly overwritten will be preserved. This means that if you store a container,
91      * its child lists will be merged.
92      *
93      * <p>
94      * This method does not automatically create missing parent nodes. It is equivalent to invoking
95      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, TreeNode, boolean)}
96      * with <code>createMissingParents</code> set to false.
97      *
98      * <p>
99      * For more information on usage and examples, please see the documentation in
100      * {@link AsyncWriteTransaction}.
101      *
102      *<p>
103      * If you require an explicit replace operation, use {@link #put} instead.
104      * @param store
105      *            the logical data store which should be modified
106      * @param path
107      *            the data object path
108      * @param data
109      *            the data object to be merged to the specified path
110      * @param <T> data tree type
111      * @throws IllegalStateException
112      *             if the transaction has already been submitted
113      */
114     <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
115
116     /**
117      * Merges a piece of data with the existing data at a specified path. Any
118      * pre-existing data which is not explicitly overwritten will be preserved.
119      * This means that if you store a container, its child lists will be merged.
120      *
121      * <p>
122      * For more information on usage and examples, please see the documentation
123      * in {@link AsyncWriteTransaction}.
124      *
125      * <p>
126      * If you require an explicit replace operation, use {@link #put} instead.
127      *
128      * @param store
129      *            the logical data store which should be modified
130      * @param path
131      *            the data object path
132      * @param data
133      *            the data object to be merged to the specified path
134      * @param createMissingParents
135      *            if {@link #CREATE_MISSING_PARENTS}, any missing parent nodes will be automatically created
136      *            using a merge operation.
137      * @param <T> data tree type
138      * @throws IllegalStateException
139      *             if the transaction has already been submitted
140      */
141     <T extends TreeNode> void merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data,
142         boolean createMissingParents);
143
144     @Override
145     void delete(LogicalDatastoreType store, InstanceIdentifier<? extends TreeNode> path);
146
147     /**
148      * Flag value indicating that missing parents should be created.
149      */
150     boolean CREATE_MISSING_PARENTS = true;
151
152     /**
153      * Flag value indicating that missing parents should cause an error.
154      */
155     boolean FAIL_ON_MISSING_PARENTS = false;
156 }