X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2FAbstractForwardedTransaction.java;h=28b63ec8b9e16856fb21b1bf423b301d194c2c8f;hb=e8046bf8787da3e07b463c5729bf0137717714f0;hp=cf2b24e2333459f0e316a50e2bdee985e5e7420b;hpb=c241dcfa5322ac10810a1068ccd2eb57f6f2dbb2;p=mdsal.git diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractForwardedTransaction.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractForwardedTransaction.java index cf2b24e233..28b63ec8b9 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractForwardedTransaction.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractForwardedTransaction.java @@ -7,59 +7,64 @@ */ package org.opendaylight.mdsal.binding.dom.adapter; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.MoreExecutors; import java.util.Optional; -import org.opendaylight.mdsal.common.api.AsyncTransaction; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadOperations; +import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction; import org.opendaylight.yangtools.concepts.Delegator; import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -abstract class AbstractForwardedTransaction>> - implements Delegator, Identifiable { +abstract class AbstractForwardedTransaction implements Delegator, + Identifiable { - private final T delegate; - private final BindingToNormalizedNodeCodec codec; + private final @NonNull BindingToNormalizedNodeCodec codec; + private final @NonNull T delegate; AbstractForwardedTransaction(final T delegateTx, final BindingToNormalizedNodeCodec codec) { - this.delegate = Preconditions.checkNotNull(delegateTx, "Delegate must not be null"); - this.codec = Preconditions.checkNotNull(codec, "Codec must not be null"); + this.delegate = requireNonNull(delegateTx, "Delegate must not be null"); + this.codec = requireNonNull(codec, "Codec must not be null"); } - @Override - public final Object getIdentifier() { + public final Object getIdentifier() { return delegate.getIdentifier(); } @Override - public final T getDelegate() { + public final T getDelegate() { return delegate; } - @SuppressWarnings("unchecked") - protected final >> S getDelegateChecked( - final Class txType) { - Preconditions.checkState(txType.isInstance(delegate)); - return (S) delegate; + protected final S getDelegateChecked(final Class txType) { + checkState(txType.isInstance(delegate)); + return txType.cast(delegate); } protected final BindingToNormalizedNodeCodec getCodec() { return codec; } - protected final FluentFuture> doRead( - final DOMDataTreeReadTransaction readTx, final LogicalDatastoreType store, + protected final @NonNull FluentFuture> doRead( + final DOMDataTreeReadOperations readOps, final LogicalDatastoreType store, final InstanceIdentifier path) { - Preconditions.checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path); + checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path); - return readTx.read(store, codec.toYangInstanceIdentifierBlocking(path)) + return readOps.read(store, codec.toYangInstanceIdentifierBlocking(path)) .transform(codec.getCodecRegistry().deserializeFunction(path)::apply, MoreExecutors.directExecutor()); } + + protected final @NonNull FluentFuture doExists(final DOMDataTreeReadOperations readOps, + final LogicalDatastoreType store, final InstanceIdentifier path) { + checkArgument(!path.isWildcarded(), "Invalid exists of wildcarded path %s", path); + return readOps.exists(store, codec.toYangInstanceIdentifierBlocking(path)); + } }