c6012bbf2183a5c71e82df7e36bb7eeb66248a28
[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,
42                     final NormalizedNode<?, ?> data) {
43         delegateWriteTx.put(store, path, data);
44     }
45
46     @Override
47     public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
48                       final NormalizedNode<?, ?> data) {
49         delegateWriteTx.merge(store, path, data);
50     }
51
52     @Override
53     public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
54         delegateWriteTx.delete(store, path);
55     }
56
57     @Override
58     public CheckedFuture<Void, TransactionCommitFailedException> submit() {
59         return delegateWriteTx.submit();
60     }
61
62     @Override
63     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
64         return delegateWriteTx.commit();
65     }
66
67     @Override
68     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
69             final LogicalDatastoreType store, final YangInstanceIdentifier path) {
70         return delegateReadTx.read(store, path);
71     }
72
73     @Override public CheckedFuture<Boolean, ReadFailedException> exists(
74         final LogicalDatastoreType store,
75         final YangInstanceIdentifier path) {
76         return delegateReadTx.exists(store, path);
77     }
78
79     @Override
80     public Object getIdentifier() {
81         return this;
82     }
83 }