6891f622d6bcf1d546ff03fc98273e151b8017a2
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / TransactionUtils.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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 package org.opendaylight.controller.sal.core.compat;
9
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.fromMdsal;
11
12 import com.google.common.util.concurrent.FluentFuture;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import java.util.Optional;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
16 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 @Deprecated
22 final class TransactionUtils {
23     private TransactionUtils() {
24
25     }
26
27     static FluentFuture<Boolean> exists(final DOMDataReadTransaction tx,
28             final LogicalDatastoreType store, final YangInstanceIdentifier path) {
29         return FluentFuture.from(tx.exists(fromMdsal(store), path));
30     }
31
32     static FluentFuture<Optional<NormalizedNode<?, ?>>> read(final DOMDataReadTransaction tx,
33             final LogicalDatastoreType store, final YangInstanceIdentifier path) {
34         return FluentFuture.from(tx.read(fromMdsal(store), path)).transform(opt -> opt.toJavaUtil(),
35             MoreExecutors.directExecutor());
36     }
37
38     static void delete(final DOMDataWriteTransaction tx, final LogicalDatastoreType store,
39             final YangInstanceIdentifier path) {
40         tx.delete(fromMdsal(store), path);
41     }
42
43     static void merge(final DOMDataWriteTransaction tx, final LogicalDatastoreType store,
44             final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
45         tx.merge(fromMdsal(store), path, data);
46     }
47
48     static void put(final DOMDataWriteTransaction tx, final LogicalDatastoreType store,
49             final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
50         tx.put(fromMdsal(store), path, data);
51     }
52 }