Bump to odlparent-9.0.0/yangtools-7.0.1-SNAPSHOT
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / store / DOMStoreReadTransaction.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 package org.opendaylight.mdsal.dom.spi.store;
9
10 import com.google.common.util.concurrent.FluentFuture;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.ReadFailedException;
15 import org.opendaylight.mdsal.dom.api.query.DOMQuery;
16 import org.opendaylight.mdsal.dom.api.query.DOMQueryResult;
17 import org.opendaylight.mdsal.dom.spi.query.DOMQueryEvaluator;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 public interface DOMStoreReadTransaction extends DOMStoreTransaction {
22     /**
23      * Reads data from provided logical data store located at provided path.
24      *
25      * @param path
26      *            Path which uniquely identifies subtree which client want to
27      *            read
28      * @return a FluentFuture containing the result of the read. The Future blocks until the
29      *         commit operation is complete. Once complete:
30      *         <ul>
31      *         <li>If the data at the supplied path exists, the Future returns an Optional object
32      *         containing the data.</li>
33      *         <li>If the data at the supplied path does not exist, the Future returns
34      *         Optional.empty().</li>
35      *         <li>If the read of the data fails, the Future will fail with a
36      *         {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
37      *         </ul>
38      */
39     FluentFuture<Optional<NormalizedNode>> read(YangInstanceIdentifier path);
40
41     /**
42      * Checks if data is available in the logical data store located at provided path.
43      *
44      * <p>
45      * Note: a successful result from this method makes no guarantee that a subsequent call to {@link #read}
46      * will succeed. It is possible that the data resides in a data store on a remote node and, if that
47      * node goes down or a network failure occurs, a subsequent read would fail. Another scenario is if
48      * the data is deleted in between the calls to <code>exists</code> and <code>read</code>
49      *
50      * @param path
51      *            Path which uniquely identifies subtree which client want to
52      *            check existence of
53      * @return a FluentFuture containing the result of the check.
54      *         <ul>
55      *         <li>If the data at the supplied path exists, the Future returns a Boolean
56      *         whose value is true, false otherwise</li>
57      *         <li>If checking for the data fails, the Future will fail with a
58      *         {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
59      *         </ul>
60      */
61     FluentFuture<Boolean> exists(YangInstanceIdentifier path);
62
63     /**
64      * Executes a query on the provided logical data store.
65      *
66      * <p>
67      * Default operation invokes {@code read(query.getRoot())} and then executes the result with
68      * {@link DOMQueryEvaluator}. Implementations are encouraged to provide a more efficient implementation as
69      * appropriate.
70      *
71      * @param query DOMQuery to execute
72      * @return a FluentFuture containing the result of the query. The Future blocks until the operation is complete.
73      *         Once complete:
74      *         <ul>
75      *           <li>The Future returns the result of the query</li>
76      *           <li>If the query execution fails, the Future will fail with a {@link ReadFailedException} or
77      *               an exception derived from ReadFailedException.
78      *            </li>
79      *         </ul>
80      * @throws NullPointerException if any of the arguments is null
81      * @throws IllegalArgumentException if the query is not supported
82      */
83     default @NonNull FluentFuture<DOMQueryResult> execute(final DOMQuery query) {
84         return read(query.getRoot()).transform(
85             node -> node.map(data -> DOMQueryEvaluator.evaluateOn(query, data)).orElse(DOMQueryResult.of()),
86             MoreExecutors.directExecutor());
87     }
88 }