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.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
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.service.AbstractDataTransaction;
19 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
20 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
28 class BindingDOMWriteTransactionAdapter<T extends DOMDataWriteTransaction> extends
29 AbstractWriteTransaction<T> implements WriteTransaction {
31 protected BindingDOMWriteTransactionAdapter(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
32 super(delegateTx, codec);
36 public <U extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<U> path,
38 put(store, path, data,false);
42 public <D extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<D> path,
44 merge(store, path, data,false);
49 protected void ensureParentsByMerge(final LogicalDatastoreType store,
50 final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath,
51 final InstanceIdentifier<?> path) {
52 List<PathArgument> currentArguments = new ArrayList<>();
53 DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
54 for (PathArgument currentArg : normalizedPath.getPathArguments()) {
56 currentOp = currentOp.getChild(currentArg);
57 } catch (DataNormalizationException e) {
58 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
60 currentArguments.add(currentArg);
61 YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(
64 getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
69 public void delete(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
70 doDelete(store, path);
74 public ListenableFuture<RpcResult<TransactionStatus>> commit() {
75 return AbstractDataTransaction.convertToLegacyCommitFuture(submit());
79 public CheckedFuture<Void,TransactionCommitFailedException> submit() {
84 public boolean cancel() {