X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FAbstractWriteTransaction.java;fp=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FAbstractWriteTransaction.java;h=0000000000000000000000000000000000000000;hp=a01b927f8650935d40ddc6c8c3eb87d71c54ca1b;hb=2611e6a728e586ea34dd891f30a473bf54d6cbd8;hpb=aaea3e9a92ae9d6fac04c4a065db4b35cbca9ed0 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractWriteTransaction.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractWriteTransaction.java deleted file mode 100644 index a01b927f86..0000000000 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractWriteTransaction.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * 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.controller.md.sal.binding.impl; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.FluentFuture; -import java.util.Map.Entry; -import org.gaul.modernizer_maven_annotations.SuppressModernizer; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.Identifiable; -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 Base Transaction for transactions which are backed by {@link DOMDataWriteTransaction}. - */ -@Deprecated(forRemoval = true) -public abstract class AbstractWriteTransaction extends - AbstractForwardedTransaction { - - protected AbstractWriteTransaction(final T delegate, final BindingToNormalizedNodeCodec codec) { - super(delegate, codec); - } - - public final void put(final LogicalDatastoreType store, - final InstanceIdentifier path, final U data, final boolean createParents) { - checkArgument(!path.isWildcarded(), "Cannot put data into wildcarded path %s", path); - - final Entry> normalized = getCodec().toNormalizedNode(path, data); - if (createParents) { - ensureParentsByMerge(store, normalized.getKey(), path); - } else { - ensureListParentIfNeeded(store,path,normalized); - } - - getDelegate().put(store, normalized.getKey(), normalized.getValue()); - } - - public final void merge(final LogicalDatastoreType store, - final InstanceIdentifier path, final U data,final boolean createParents) { - checkArgument(!path.isWildcarded(), "Cannot merge data into wildcarded path %s", path); - - final Entry> normalized = getCodec().toNormalizedNode(path, data); - if (createParents) { - ensureParentsByMerge(store, normalized.getKey(), path); - } else { - ensureListParentIfNeeded(store,path,normalized); - } - - getDelegate().merge(store, normalized.getKey(), normalized.getValue()); - } - - /** - * Ensures list parent if item is list, otherwise noop. - * - *

- * One of properties of binding specification is that it is imposible - * to represent list as a whole and thus it is impossible to write - * empty variation of MapNode without creating parent node, with - * empty list. - * - *

- * This actually makes writes such as - *

-     * put("Nodes", new NodesBuilder().build());
-     * put("Nodes/Node[key]", new NodeBuilder().setKey("key").build());
-     * 
- * To result in three DOM operations: - *
-     * put("/nodes",domNodes);
-     * merge("/nodes/node",domNodeList);
-     * put("/nodes/node/node[key]",domNode);
-     * 
- * - *

- * In order to allow that to be inserted if necessary, if we know - * item is list item, we will try to merge empty MapNode or OrderedNodeMap - * to ensure list exists. - * - * @param store Data Store type - * @param path Path to data (Binding Aware) - * @param normalized Normalized version of data to be written - */ - private void ensureListParentIfNeeded(final LogicalDatastoreType store, final InstanceIdentifier path, - final Entry> normalized) { - if (Identifiable.class.isAssignableFrom(path.getTargetType())) { - YangInstanceIdentifier parentMapPath = normalized.getKey().getParent(); - checkArgument(parentMapPath != null, "Map path %s does not have a parent", path); - - NormalizedNode emptyParent = getCodec().getDefaultNodeFor(parentMapPath); - getDelegate().merge(store, parentMapPath, emptyParent); - } - } - - /** - * Deprecated. - * - * @deprecated Use {@link YangInstanceIdentifier#getParent()} instead. - */ - @Deprecated - @SuppressModernizer - protected static Optional getParent(final YangInstanceIdentifier child) { - return Optional.fromNullable(child.getParent()); - } - - /** - * Subclasses of this class are required to implement creation of parent - * nodes based on behaviour of their underlying transaction. - */ - protected abstract void ensureParentsByMerge(LogicalDatastoreType store, - YangInstanceIdentifier key, InstanceIdentifier path); - - protected final void doDelete(final LogicalDatastoreType store, - final InstanceIdentifier path) { - checkArgument(!path.isWildcarded(), "Cannot delete wildcarded path %s", path); - - final YangInstanceIdentifier normalized = getCodec().toYangInstanceIdentifierBlocking(path); - getDelegate().delete(store, normalized); - } - - protected final FluentFuture doCommit() { - return getDelegate().commit(); - } - - protected final boolean doCancel() { - return getDelegate().cancel(); - } -}