162e8be0467604ee6777625d44d6948a8ad3afc5
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / transactions / RestconfTransaction.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, 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.restconf.nb.rfc8040.rests.transactions;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.FluentFuture;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.common.api.CommitInfo;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 /**
20  * A handle to a set of operations being executed atomically on top of some backing store.
21  */
22 // FIXME: it seems the first two operations deal with lifecycle of a transaction, while others invoke various
23 //        operations. This should be handled through proper allocation indirection.
24 @Beta
25 public abstract class RestconfTransaction {
26     RestconfTransaction() {
27         // Hidden on purpose
28     }
29
30     /**
31      * Rollback changes and unlock the datastore.
32      */
33     // FIXME: this looks synchronous, but it should not be
34     public abstract void cancel();
35
36     /**
37      * Confirm previous operations.
38      *
39      * @return a FluentFuture containing the result of the commit information
40      */
41     public abstract FluentFuture<? extends @NonNull CommitInfo> commit();
42
43     /**
44      * Delete data from the datastore.
45      *
46      * @param store the logical data store which should be modified
47      * @param path the data object path
48      */
49     public abstract void delete(LogicalDatastoreType store, YangInstanceIdentifier path);
50
51     /**
52      * Remove data from the datastore.
53      *
54      * @param store the logical data store which should be modified
55      * @param path  the data object path
56      */
57     public abstract void remove(LogicalDatastoreType store, YangInstanceIdentifier path);
58
59     /**
60      * Merges a piece of data with the existing data at a specified path.
61      *
62      * @param store the logical data store which should be modified
63      * @param path the data object path
64      * @param data the data object to be merged to the specified path
65      */
66     public abstract void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data);
67
68     /**
69      * Stores a piece of data at the specified path.
70      *
71      * @param store         the logical data store which should be modified
72      * @param path          the data object path
73      * @param data          the data object to be merged to the specified path
74      * @param schemaContext static view of compiled yang files
75      */
76     public abstract void create(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data,
77                                 SchemaContext schemaContext);
78
79     /**
80      * Replace a piece of data at the specified path.
81      *
82      * @param store         the logical data store which should be modified
83      * @param path          the data object path
84      * @param data          the data object to be merged to the specified path
85      * @param schemaContext static view of compiled yang files
86      */
87     public abstract void replace(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode data,
88                                  SchemaContext schemaContext);
89 }