Do not allow multi-datastore transactions
[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 com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.common.api.TransactionDatastoreMismatchException;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16
17 /**
18  * Write-like operations supported by {@link WriteTransaction} and {@link ReadWriteTransaction}. This interface defines
19  * the operations without a tie-in with lifecycle management.
20  */
21 public interface WriteOperations {
22     /**
23      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that
24      * whole subtree will be replaced by the specified data.
25      *
26      * <p>
27      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
28      * put, consider using {@link #merge} instead.
29      *
30      * @param store the logical data store which should be modified
31      * @param path the data object path
32      * @param data the data object to be written to the specified path
33      * @throws IllegalStateException if the transaction has already been submitted
34      * @throws NullPointerException if any of the arguments is {@code null}
35      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
36      */
37     <T extends DataObject> void put(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
38             @NonNull T data);
39
40     /**
41      * Stores a piece of data at the specified path. This acts as an add / replace operation, which is to say that whole
42      * subtree will be replaced by the specified data. Unlike
43      * {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
44      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
45      *
46      * <p>
47      * If you need to make sure that a parent object exists but you do not want modify its pre-existing state by using
48      * put, consider using {@link #merge} instead.
49      *
50      * <p>
51      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
52      *                 a previous transaction. It also has a significantly higher cost than
53      *                 {@link #put(LogicalDatastoreType, InstanceIdentifier, DataObject)} and should only be used when
54      *                 absolutely necessary.
55      *
56      * @param store the logical data store which should be modified
57      * @param path the data object path
58      * @param data the data object to be written to the specified path
59      * @throws IllegalStateException if the transaction has already been submitted
60      * @throws NullPointerException if any of the arguments is {@code null}
61      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
62      */
63     // TODO: can we come up with a better name?
64     @Beta
65     <T extends DataObject> void mergeParentStructurePut(@NonNull LogicalDatastoreType store,
66             @NonNull InstanceIdentifier<T> path, @NonNull T data);
67
68     /**
69      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
70      * overwritten will be preserved. This means that if you store a container, its child lists will be merged.
71      *
72      * <p>
73      * If you require an explicit replace operation, use {@link #put} instead.
74      *
75      * @param store the logical data store which should be modified
76      * @param path the data object path
77      * @param data the data object to be merged to the specified path
78      * @throws IllegalStateException if the transaction has already been submitted
79      * @throws NullPointerException if any of the arguments is {@code null}
80      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
81      */
82     <T extends DataObject> void merge(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<T> path,
83             @NonNull T data);
84
85     /**
86      * Merges a piece of data with the existing data at a specified path. Any pre-existing data which is not explicitly
87      * overwritten will be preserved. This means that if you store a container, its child lists will be merged. Unlike
88      * {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}, this method will attempt to create
89      * semantically-significant parent nodes, like list entries and presence containers, as indicated by {@code path}.
90      *
91      * <p>
92      * If you require an explicit replace operation, use {@link #put} instead.
93      *
94      * <p>
95      * <b>WARNING:</b> Using this method may introduce garbage in data store, or recreate nodes, which were deleted by
96      *                 a previous transaction. It is not necessary in most scenarios and has a significantly higher cost
97      *                 than {@link #merge(LogicalDatastoreType, InstanceIdentifier, DataObject)}. It should only be used
98      *                 when absolutely necessary.
99      *
100      * @param store the logical data store which should be modified
101      * @param path the data object path
102      * @param data the data object to be merged to the specified path
103      * @throws IllegalStateException if the transaction has already been submitted
104      * @throws NullPointerException if any of the arguments is {@code null}
105      * @throws TransactionDatastoreMismatchException if this transaction is already bound to a different data store
106      */
107     // TODO: can we come up with a better name?
108     @Beta
109     <T extends DataObject> void mergeParentStructureMerge(@NonNull LogicalDatastoreType store,
110             @NonNull InstanceIdentifier<T> path, @NonNull T data);
111
112     /**
113      * Removes a piece of data from specified path. This operation does not fail if the specified path does not exist.
114      *
115      * @param store Logical data store which should be modified
116      * @param path Data object path
117      * @throws IllegalStateException if the transaction was committed or canceled.
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      */
121     void delete(@NonNull LogicalDatastoreType store, @NonNull InstanceIdentifier<?> path);
122 }