Migrate netconf to MD-SAL APIs
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / sal / tx / ReadWriteTx.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
9 package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
10
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.CommitInfo;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21
22 public class ReadWriteTx implements DOMDataTreeReadWriteTransaction {
23
24     private final DOMDataTreeReadTransaction delegateReadTx;
25     private final DOMDataTreeWriteTransaction delegateWriteTx;
26
27     public ReadWriteTx(final DOMDataTreeReadTransaction delegateReadTx,
28             final DOMDataTreeWriteTransaction delegateWriteTx) {
29         this.delegateReadTx = delegateReadTx;
30         this.delegateWriteTx = delegateWriteTx;
31     }
32
33     @Override
34     public boolean cancel() {
35         return delegateWriteTx.cancel();
36     }
37
38     @Override
39     public void close() {
40         cancel();
41     }
42
43     @Override
44     public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
45                     final NormalizedNode<?, ?> data) {
46         delegateWriteTx.put(store, path, data);
47     }
48
49     @Override
50     public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
51                       final NormalizedNode<?, ?> data) {
52         delegateWriteTx.merge(store, path, data);
53     }
54
55     @Override
56     public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
57         delegateWriteTx.delete(store, path);
58     }
59
60     @Override
61     public FluentFuture<? extends @NonNull CommitInfo> commit() {
62         return delegateWriteTx.commit();
63     }
64
65     @Override
66     public FluentFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store,
67             final YangInstanceIdentifier path) {
68         return delegateReadTx.read(store, path);
69     }
70
71     @Override
72     public FluentFuture<Boolean> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
73         return delegateReadTx.exists(store, path);
74     }
75
76     @Override
77     public Object getIdentifier() {
78         return this;
79     }
80 }