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