import com.google.common.collect.ForwardingObject;
import com.google.common.util.concurrent.FluentFuture;
import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
public static ReadWriteTransaction toReadWriteTransaction(
final TypedReadWriteTransaction<? extends Datastore> datastoreTx) {
if (datastoreTx instanceof TypedReadWriteTransactionImpl) {
- TypedReadWriteTransactionImpl nonSubmitCancelableDatastoreReadWriteTransaction =
- (TypedReadWriteTransactionImpl) datastoreTx;
- return new ReadWriteTransactionAdapter(nonSubmitCancelableDatastoreReadWriteTransaction.datastoreType,
- nonSubmitCancelableDatastoreReadWriteTransaction);
+ final TypedReadWriteTransactionImpl<?> txImpl = (TypedReadWriteTransactionImpl<?>) datastoreTx;
+ return new ReadWriteTransactionAdapter<>(txImpl.getDatastoreType(), txImpl);
}
- throw new IllegalArgumentException(
- "Unsupported TypedWriteTransaction implementation " + datastoreTx.getClass());
+ throw new IllegalArgumentException("Unsupported TypedWriteTransaction implementation "
+ + datastoreTx.getClass());
}
/**
*/
public static WriteTransaction toWriteTransaction(final TypedWriteTransaction<? extends Datastore> datastoreTx) {
if (datastoreTx instanceof TypedWriteTransactionImpl) {
- TypedWriteTransactionImpl nonSubmitCancelableDatastoreWriteTransaction =
- (TypedWriteTransactionImpl) datastoreTx;
- return new WriteTransactionAdapter(nonSubmitCancelableDatastoreWriteTransaction.datastoreType,
- nonSubmitCancelableDatastoreWriteTransaction);
+ final TypedWriteTransactionImpl<?, ?> txImpl = (TypedWriteTransactionImpl<?, ?>) datastoreTx;
+ return new WriteTransactionAdapter<>(txImpl.getDatastoreType(), txImpl);
}
- throw new IllegalArgumentException(
- "Unsupported TypedWriteTransaction implementation " + datastoreTx.getClass());
+ throw new IllegalArgumentException("Unsupported TypedWriteTransaction implementation "
+ + datastoreTx.getClass());
}
- // We want to subclass this class, even though it has a private constructor
- @SuppressWarnings("FinalClass")
- private static class WriteTransactionAdapter<D extends Datastore, T extends TypedWriteTransaction<D>>
+ private static class WriteTransactionAdapter<S extends Datastore, D extends TypedWriteTransaction<S>>
extends ForwardingObject implements WriteTransaction {
private final LogicalDatastoreType datastoreType;
- private final T delegate;
+ private final D delegate;
- private WriteTransactionAdapter(final LogicalDatastoreType datastoreType, final T delegate) {
+ WriteTransactionAdapter(final LogicalDatastoreType datastoreType, final D delegate) {
this.datastoreType = datastoreType;
this.delegate = delegate;
}
}
@Override
- public <T extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
- final T data, final boolean createMissingParents) {
+ public <T extends DataObject> void mergeParentStructurePut(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path, final T data) {
checkStore(store);
- delegate.put(path, data, createMissingParents);
+ delegate.mergeParentStructurePut(path, data);
}
@Override
}
@Override
- public <T extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
- final T data, final boolean createMissingParents) {
+ public <T extends DataObject> void mergeParentStructureMerge(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path, final T data) {
checkStore(store);
- delegate.merge(path, data, createMissingParents);
+ delegate.mergeParentStructureMerge(path, data);
}
@Override
}
@Override
- public @NonNull FluentFuture<? extends CommitInfo> commit() {
+ public FluentFuture<? extends CommitInfo> commit() {
throw new UnsupportedOperationException("Managed transactions must not be committed");
}
- void checkStore(final LogicalDatastoreType store) {
- checkArgument(datastoreType.equals(store), "Invalid datastore %s used instead of %s", store, datastoreType);
- }
-
@Override
public Object getIdentifier() {
return delegate.getIdentifier();
}
@Override
- protected T delegate() {
+ public FluentFuture<?> completionFuture() {
+ return delegate.completionFuture();
+ }
+
+ @Override
+ protected D delegate() {
return delegate;
}
+
+ void checkStore(final LogicalDatastoreType store) {
+ checkArgument(datastoreType.equals(store), "Invalid datastore %s used instead of %s", store, datastoreType);
+ }
}
- private static final class ReadWriteTransactionAdapter<D extends Datastore>
- extends WriteTransactionAdapter<D, TypedReadWriteTransaction<D>> implements ReadWriteTransaction {
- private ReadWriteTransactionAdapter(final LogicalDatastoreType datastoreType,
- final TypedReadWriteTransaction<D> delegate) {
+ private static final class ReadWriteTransactionAdapter<S extends Datastore>
+ extends WriteTransactionAdapter<S, TypedReadWriteTransaction<S>> implements ReadWriteTransaction {
+ ReadWriteTransactionAdapter(final LogicalDatastoreType datastoreType,
+ final TypedReadWriteTransaction<S> delegate) {
super(datastoreType, delegate);
}
checkStore(store);
return delegate().read(path);
}
+
+ @Override
+ public FluentFuture<Boolean> exists(final LogicalDatastoreType store,final InstanceIdentifier<?> path) {
+ checkStore(store);
+ return delegate().exists(path);
+ }
}
}