2 * Copyright © 2018 Red Hat, Inc. and others.
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.binding.util;
10 import com.google.common.util.concurrent.FluentFuture;
11 import org.opendaylight.mdsal.binding.api.QueryOperations;
12 import org.opendaylight.mdsal.binding.api.Transaction;
13 import org.opendaylight.mdsal.binding.api.query.QueryExpression;
14 import org.opendaylight.mdsal.binding.api.query.QueryResult;
15 import org.opendaylight.mdsal.binding.spi.ForwardingTransaction;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
19 abstract class TypedTransaction<D extends Datastore, X extends Transaction> extends ForwardingTransaction {
20 private final LogicalDatastoreType datastoreType;
21 private final X delegate;
23 TypedTransaction(final D datastore, final X delegate) {
24 this.datastoreType = datastore.type();
25 this.delegate = delegate;
29 protected final X delegate() {
33 final LogicalDatastoreType getDatastoreType() {
37 final <T extends DataObject> FluentFuture<QueryResult<T>> doExecute(final QueryExpression<T> query) {
38 if (delegate instanceof QueryOperations queryOps) {
39 return queryOps.execute(datastoreType, query);
41 throw new UnsupportedOperationException("Query execution requires backend support");