Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-api / src / main / java / org / opendaylight / controller / md / sal / binding / api / ReadTransaction.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.controller.md.sal.binding.api;
9
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncReadTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20
21 /**
22  * A transaction that provides read access to a logical data store.
23  *
24  * <p>
25  * For more information on usage and examples, please see the documentation in {@link AsyncReadTransaction}.
26  *
27  * @deprecated Use {@link org.opendaylight.mdsal.binding.api.ReadTransaction} instead.
28  */
29 @Deprecated
30 public interface ReadTransaction extends AsyncReadTransaction<InstanceIdentifier<?>, DataObject> {
31
32     /**
33      * Reads data from the provided logical data store located at the provided path.
34      *<p>
35      * If the target is a subtree, then the whole subtree is read (and will be
36      * accessible from the returned data object).
37      *
38      * @param store
39      *            Logical data store from which read should occur.
40      * @param path
41      *            Path which uniquely identifies subtree which client want to
42      *            read
43      * @return a CheckFuture containing the result of the read. The Future blocks until the
44      *         commit operation is complete. Once complete:
45      *         <ul>
46      *         <li>If the data at the supplied path exists, the Future returns an Optional object
47      *         containing the data.</li>
48      *         <li>If the data at the supplied path does not exist, the Future returns
49      *         Optional#absent().</li>
50      *         <li>If the read of the data fails, the Future will fail with a
51      *         {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
52      *         </ul>
53      */
54     <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(
55             LogicalDatastoreType store, InstanceIdentifier<T> path);
56
57     /**
58      * Checks if data is available in the logical data store located at provided path.
59      *
60      * <p>
61      * Note: a successful result from this method makes no guarantee that a subsequent call to {@link #read}
62      * will succeed. It is possible that the data resides in a data store on a remote node and, if that
63      * node goes down or a network failure occurs, a subsequent read would fail. Another scenario is if
64      * the data is deleted in between the calls to <code>exists</code> and <code>read</code>
65      *
66      * <p>
67      * Default implementation delegates to {@link #read(LogicalDatastoreType, InstanceIdentifier)}, implementations
68      * are advised to provide a more efficient override.
69      *
70      * @param store
71      *            Logical data store from which read should occur.
72      * @param path
73      *            Path which uniquely identifies subtree which client want to
74      *            check existence of
75      * @return a CheckFuture containing the result of the check.
76      *         <ul>
77      *         <li>If the data at the supplied path exists, the Future returns a Boolean
78      *         whose value is true, false otherwise</li>
79      *         <li>If checking for the data fails, the Future will fail with a
80      *         {@link ReadFailedException} or an exception derived from ReadFailedException.</li>
81      *         </ul>
82      */
83     default CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
84             final InstanceIdentifier<?> path) {
85         return MappingCheckedFuture.create(Futures.transform(read(store, path), Optional::isPresent,
86             MoreExecutors.directExecutor()), ReadFailedException.MAPPER);
87     }
88 }