2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.spi.store;
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;
21 public interface DOMStoreReadTransaction extends DOMStoreTransaction {
23 * Reads data from provided logical data store located at provided path.
26 * Path which uniquely identifies subtree which client want to
28 * @return a FluentFuture containing the result of the read. The Future blocks until the
29 * commit operation is complete. Once complete:
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>
39 FluentFuture<Optional<NormalizedNode>> read(YangInstanceIdentifier path);
42 * Checks if data is available in the logical data store located at provided path.
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>
51 * Path which uniquely identifies subtree which client want to
53 * @return a FluentFuture containing the result of the check.
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>
61 FluentFuture<Boolean> exists(YangInstanceIdentifier path);
64 * Executes a query on the provided logical data store.
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
71 * @param query DOMQuery to execute
72 * @return a FluentFuture containing the result of the query. The Future blocks until the operation is complete.
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.
80 * @throws NullPointerException if any of the arguments is null
81 * @throws IllegalArgumentException if the query is not supported
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());