Move netconf-console to apps/
[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<T extends DOMDataTreeReadTransaction> implements DOMDataTreeReadWriteTransaction {
23     private final DOMDataTreeWriteTransaction delegateWriteTx;
24     final T delegateReadTx;
25
26     public ReadWriteTx(final T delegateReadTx, final DOMDataTreeWriteTransaction delegateWriteTx) {
27         this.delegateReadTx = delegateReadTx;
28         this.delegateWriteTx = delegateWriteTx;
29     }
30
31     @Override
32     public final boolean cancel() {
33         return delegateWriteTx.cancel();
34     }
35
36     @Override
37     public final void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
38                           final NormalizedNode data) {
39         delegateWriteTx.put(store, path, data);
40     }
41
42     @Override
43     public final void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
44                             final NormalizedNode data) {
45         delegateWriteTx.merge(store, path, data);
46     }
47
48     @Override
49     public final void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
50         delegateWriteTx.delete(store, path);
51     }
52
53     @Override
54     public final FluentFuture<? extends @NonNull CommitInfo> commit() {
55         return delegateWriteTx.commit();
56     }
57
58     @Override
59     public final FluentFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
60             final YangInstanceIdentifier path) {
61         return delegateReadTx.read(store, path);
62     }
63
64     @Override
65     public final FluentFuture<Boolean> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
66         return delegateReadTx.exists(store, path);
67     }
68
69     @Override
70     public final Object getIdentifier() {
71         return this;
72     }
73 }