b063cba63ac8603861b9a387ff79dd5a42b43bf6
[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.base.Optional;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24
25 public class ReadWriteTx implements DOMDataReadWriteTransaction {
26
27     private final DOMDataReadTransaction delegateReadTx;
28     private final DOMDataWriteTransaction delegateWriteTx;
29
30     public ReadWriteTx(final DOMDataReadTransaction delegateReadTx, final DOMDataWriteTransaction delegateWriteTx) {
31         this.delegateReadTx = delegateReadTx;
32         this.delegateWriteTx = delegateWriteTx;
33     }
34
35     @Override
36     public boolean cancel() {
37         return delegateWriteTx.cancel();
38     }
39
40     @Override
41     public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
42         delegateWriteTx.put(store, path, data);
43     }
44
45     @Override
46     public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
47         delegateWriteTx.merge(store, path, data);
48     }
49
50     @Override
51     public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
52         delegateWriteTx.delete(store, path);
53     }
54
55     @Override
56     public CheckedFuture<Void, TransactionCommitFailedException> submit() {
57         return delegateWriteTx.submit();
58     }
59
60     @Override
61     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
62         return delegateWriteTx.commit();
63     }
64
65     @Override
66     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
67             final LogicalDatastoreType store, final YangInstanceIdentifier path) {
68         return delegateReadTx.read(store, path);
69     }
70
71     @Override public CheckedFuture<Boolean, ReadFailedException> exists(
72         final LogicalDatastoreType store,
73         final YangInstanceIdentifier path) {
74         return delegateReadTx.exists(store, path);
75     }
76
77     @Override
78     public Object getIdentifier() {
79         return this;
80     }
81 }