2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.v3po.data.impl;
19 import com.google.common.base.Optional;
20 import com.google.common.base.Preconditions;
21 import com.google.common.util.concurrent.CheckedFuture;
22 import com.google.common.util.concurrent.ListenableFuture;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
27 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
28 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
29 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
30 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
34 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
37 * Composite DOM transaction that delegates reads to a {@link DOMDataReadTransaction} delegate and writes to a {@link
38 * DOMDataWriteTransaction} delegate.
40 final class ReadWriteTransaction implements DOMDataReadWriteTransaction {
42 private final DOMDataReadOnlyTransaction delegateReadTx;
43 private final DOMDataWriteTransaction delegateWriteTx;
45 ReadWriteTransaction(@Nonnull final DOMDataReadOnlyTransaction delegateReadTx,
46 @Nonnull final DOMDataWriteTransaction delegateWriteTx) {
47 this.delegateReadTx = Preconditions.checkNotNull(delegateReadTx, "delegateReadTx should not be null");
48 this.delegateWriteTx = Preconditions.checkNotNull(delegateWriteTx, "delegateWriteTx should not be null");
52 public boolean cancel() {
53 delegateReadTx.close();
54 return delegateWriteTx.cancel();
58 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
59 final NormalizedNode<?, ?> data) {
60 delegateWriteTx.put(store, path, data);
64 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
65 final NormalizedNode<?, ?> data) {
66 delegateWriteTx.merge(store, path, data);
70 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
71 delegateWriteTx.delete(store, path);
75 public CheckedFuture<Void, TransactionCommitFailedException> submit() {
76 return delegateWriteTx.submit();
80 public ListenableFuture<RpcResult<TransactionStatus>> commit() {
81 return delegateWriteTx.commit();
85 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
86 final YangInstanceIdentifier path) {
87 return delegateReadTx.read(store, path);
91 public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
92 final YangInstanceIdentifier path) {
93 return delegateReadTx.exists(store, path);
97 public Object getIdentifier() {