A query needs to result in a set of path/object tuples, as we really
need to discern matches. Having a concrete path of matches helps
getting identifiers of parent objects for subquent queries.
DOMQueryResult already contains this capability, we just need to
propagate it.
JIRA: MDSAL-604
Change-Id: Iec9ad34aac105eeb45c26a31a24611c9e0f2bb82
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.annotations.Beta;
import com.google.common.util.concurrent.ListenableFuture;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.yang.binding.DataObject;
@Beta
import org.opendaylight.yangtools.yang.binding.DataObject;
@Beta
public interface QueryExecutor {
<T extends DataObject> ListenableFuture<? extends QueryResult<T>> executeQuery(QueryExpression<T> query);
public interface QueryExecutor {
<T extends DataObject> ListenableFuture<? extends QueryResult<T>> executeQuery(QueryExpression<T> query);
*/
package org.opendaylight.mdsal.binding.api.query;
*/
package org.opendaylight.mdsal.binding.api.query;
-import com.google.common.annotations.Beta;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* Result of executing a {@link QueryExpression}. It is composed of one or more result values, which can be accessed via
/**
* Result of executing a {@link QueryExpression}. It is composed of one or more result values, which can be accessed via
*
* @param <T> Result object type
*/
*
* @param <T> Result object type
*/
public interface QueryResult<T extends DataObject> {
public interface QueryResult<T extends DataObject> {
+ /**
+ * A single item in the result set. It is identified by its path and the corresponding object..
+ *
+ * @param <T> Result object type
+ */
+ interface Item<T extends DataObject> extends Immutable {
+ /**
+ * Return the result object.
+ *
+ * @return Result object
+ */
+ T object();
+
+ /**
+ * Return the {@link InstanceIdentifier} of the result object. This is guaranteed to be non-wildcard.
+ *
+ * @return InstanceIdentifier of the result object
+ */
+ InstanceIdentifier<T> path();
+ }
+
/**
* Returns a spliterator over values of the result.
*
/**
* Returns a spliterator over values of the result.
*
*/
// TODO: @throws IllegalStateException if values have been already been consumed?
// FIXME: we really may want to wrap each entry in a CheckedValue, so that we can communicate fetch problems
*/
// TODO: @throws IllegalStateException if values have been already been consumed?
// FIXME: we really may want to wrap each entry in a CheckedValue, so that we can communicate fetch problems
- @NonNull Spliterator<? extends T> spliterator();
+ Spliterator<? extends Item<T>> spliterator();
/**
* Returns a sequential {@link Stream} of values from the result.
*
* @return A stream of non-null values.
*/
/**
* Returns a sequential {@link Stream} of values from the result.
*
* @return A stream of non-null values.
*/
- default @NonNull Stream<? extends T> stream() {
+ default Stream<? extends Item<T>> stream() {
return StreamSupport.stream(spliterator(), false);
}
return StreamSupport.stream(spliterator(), false);
}
*
* @return A stream of non-null values.
*/
*
* @return A stream of non-null values.
*/
- default @NonNull Stream<? extends T> parallelStream() {
+ default Stream<? extends Item<T>> parallelStream() {
return StreamSupport.stream(spliterator(), true);
}
return StreamSupport.stream(spliterator(), true);
}
- default @NonNull List<? extends T> getValues() {
+ default List<? extends T> getValues() {
+ return stream().map(Item::object).collect(Collectors.toUnmodifiableList());
+ }
+
+ default List<? extends Item<T>> getItems() {
return stream().collect(Collectors.toUnmodifiableList());
}
}
return stream().collect(Collectors.toUnmodifiableList());
}
}