2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import com.google.common.util.concurrent.CheckedFuture;
11 import com.google.common.util.concurrent.FluentFuture;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
19 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
20 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
21 import org.opendaylight.controller.md.sal.dom.broker.impl.TransactionCommitFailedExceptionMapper;
22 import org.opendaylight.mdsal.common.api.CommitInfo;
23 import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
29 class BindingDOMWriteTransactionAdapter<T extends DOMDataWriteTransaction> extends
30 AbstractWriteTransaction<T> implements WriteTransaction {
32 protected BindingDOMWriteTransactionAdapter(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
33 super(delegateTx, codec);
37 public <U extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<U> path,
39 put(store, path, data,false);
43 public <D extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<D> path,
45 merge(store, path, data,false);
50 protected void ensureParentsByMerge(final LogicalDatastoreType store,
51 final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath,
52 final InstanceIdentifier<?> path) {
53 List<PathArgument> currentArguments = new ArrayList<>();
54 DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
55 for (PathArgument currentArg : normalizedPath.getPathArguments()) {
57 currentOp = currentOp.getChild(currentArg);
58 } catch (DataNormalizationException e) {
59 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
61 currentArguments.add(currentArg);
62 YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(
65 getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
70 public void delete(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
71 doDelete(store, path);
75 public CheckedFuture<Void,TransactionCommitFailedException> submit() {
76 return MappingCheckedFuture.create(commit().transform(ignored -> null,
77 MoreExecutors.directExecutor()), TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
81 public FluentFuture<? extends CommitInfo> commit() {
86 public boolean cancel() {