/* * 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 static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ForwardingObject; import com.google.common.util.concurrent.FluentFuture; import java.util.Optional; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.ReadWriteTransaction; import org.opendaylight.mdsal.binding.api.WriteTransaction; import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** * Adapter allowing managed, datastore-constrained transactions to be used with methods expecting * generic {@link DataBroker} transactions. * *
The adapted transactions maintain the following constraints: they cannot be cancelled or
* submitted (only the transaction manager can do this), and they cannot access a logical datastore
* other than the one they were created for.
*
* @deprecated This is only intended for temporary use during complex migrations to managed transactions.
*/
@Deprecated
public final class TransactionAdapter {
private TransactionAdapter() {
}
/**
* Adapts the given datastore-constrained read-write transaction to a generic read-write transaction.
*
* @param datastoreTx The transaction to adapt.
* @return The adapted transaction.
* @throws NullPointerException if the provided transaction is {@code null}.
*/
public static ReadWriteTransaction toReadWriteTransaction(
final TypedReadWriteTransaction extends Datastore> datastoreTx) {
if (datastoreTx instanceof TypedReadWriteTransactionImpl) {
final TypedReadWriteTransactionImpl> txImpl = (TypedReadWriteTransactionImpl>) datastoreTx;
return new ReadWriteTransactionAdapter<>(txImpl.getDatastoreType(), txImpl);
}
throw new IllegalArgumentException("Unsupported TypedWriteTransaction implementation "
+ datastoreTx.getClass());
}
/**
* Adapts the given datastore-constrained write transaction to a generic write transaction. Note that this
* can be used to adapt a read-write transaction to a write transaction.
*
* @param datastoreTx The transaction to adapt.
* @return The adapted transaction.
*/
public static WriteTransaction toWriteTransaction(final TypedWriteTransaction extends Datastore> datastoreTx) {
if (datastoreTx instanceof TypedWriteTransactionImpl) {
final TypedWriteTransactionImpl, ?> txImpl = (TypedWriteTransactionImpl, ?>) datastoreTx;
return new WriteTransactionAdapter<>(txImpl.getDatastoreType(), txImpl);
}
throw new IllegalArgumentException("Unsupported TypedWriteTransaction implementation "
+ datastoreTx.getClass());
}
private static class WriteTransactionAdapter>
extends ForwardingObject implements WriteTransaction {
private final LogicalDatastoreType datastoreType;
private final D delegate;
WriteTransactionAdapter(final LogicalDatastoreType datastoreType, final D delegate) {
this.datastoreType = datastoreType;
this.delegate = delegate;
}
@Override
public
extends WriteTransactionAdapter> implements ReadWriteTransaction {
ReadWriteTransactionAdapter(final LogicalDatastoreType datastoreType,
final TypedReadWriteTransaction delegate) {
super(datastoreType, delegate);
}
@Override
public