/* * Copyright © 2018 Red Hat, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.util; import com.google.common.util.concurrent.FluentFuture; import org.opendaylight.mdsal.binding.api.QueryOperations; import org.opendaylight.mdsal.binding.api.Transaction; import org.opendaylight.mdsal.binding.api.query.QueryExpression; import org.opendaylight.mdsal.binding.api.query.QueryResult; import org.opendaylight.mdsal.binding.spi.ForwardingTransaction; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.binding.DataObject; abstract class TypedTransaction extends ForwardingTransaction { private final LogicalDatastoreType datastoreType; private final X delegate; TypedTransaction(final Class datastoreType, final X delegate) { this.datastoreType = Datastore.toType(datastoreType); this.delegate = delegate; } @Override protected final X delegate() { return delegate; } final LogicalDatastoreType getDatastoreType() { return datastoreType; } final FluentFuture> doExecute(final QueryExpression query) { if (delegate instanceof QueryOperations) { return ((QueryOperations) delegate).execute(datastoreType, query); } throw new UnsupportedOperationException("Query execution requires backend support"); } }