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;h=f8c56f95b3aaa26848faca888085bf790446f503;hp=a8eef5a3cae2687f6cc552454407e0bb8bf9eb97;hb=45d8b39b7584805d173a143e77dbff671b60f97f;hpb=2f1946537e63cc66950d4359b77fd49dbe1bdea3 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 index a8eef5a3ca..f8c56f95b3 100644 --- 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 @@ -30,7 +30,7 @@ import com.google.common.util.concurrent.CheckedFuture; * Abstract Base Transaction for transactions which are backed by * {@link DOMDataWriteTransaction} */ -public class AbstractWriteTransaction extends +public abstract class AbstractWriteTransaction extends AbstractForwardedTransaction { private static final Logger LOG = LoggerFactory.getLogger(AbstractWriteTransaction.class); @@ -40,15 +40,36 @@ public class AbstractWriteTransaction extends super(delegate, codec); } - protected final void doPut(final LogicalDatastoreType store, - final InstanceIdentifier path, final DataObject data) { + + public final void put(final LogicalDatastoreType store, + final InstanceIdentifier path, final U data, final boolean createParents) { final Entry> normalized = getCodec() .toNormalizedNode(path, data); - ensureListParentIfNeeded(store,path,normalized); + 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) { + + 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. @@ -106,14 +127,16 @@ public class AbstractWriteTransaction extends } } - protected final void doMerge(final LogicalDatastoreType store, - final InstanceIdentifier path, final DataObject data) { - - final Entry> normalized = getCodec() - .toNormalizedNode(path, data); - ensureListParentIfNeeded(store,path,normalized); - getDelegate().merge(store, normalized.getKey(), normalized.getValue()); - } + /** + * Subclasses of this class are required to implement creation of parent + * nodes based on behaviour of their underlying transaction. + * + * @param store + * @param key + * @param path + */ + protected abstract void ensureParentsByMerge(LogicalDatastoreType store, + org.opendaylight.yangtools.yang.data.api.InstanceIdentifier key, InstanceIdentifier path); protected final void doDelete(final LogicalDatastoreType store, final InstanceIdentifier path) {