BUG-1092: adjust to YangInstanceIdentifier
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDataWriteTransactionImpl.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl;
9
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13
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.PathArgument;
26
27 import com.google.common.util.concurrent.CheckedFuture;
28 import com.google.common.util.concurrent.ListenableFuture;
29
30 class BindingDataWriteTransactionImpl<T extends DOMDataWriteTransaction> extends
31         AbstractWriteTransaction<T> implements WriteTransaction {
32
33     protected BindingDataWriteTransactionImpl(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
34         super(delegateTx, codec);
35     }
36
37     @Override
38     public <U extends DataObject> void put(final LogicalDatastoreType store, final InstanceIdentifier<U> path,
39                                            final U data) {
40         put(store, path, data,false);
41     }
42
43     @Override
44     public <T extends DataObject> void merge(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
45                                              final T data) {
46         merge(store, path, data,false);
47     }
48
49
50     @Override
51     protected void ensureParentsByMerge(final LogicalDatastoreType store,
52             final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath, final InstanceIdentifier<?> path) {
53         List<PathArgument> currentArguments = new ArrayList<>();
54         DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
55         Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
56         while (iterator.hasNext()) {
57             PathArgument currentArg = iterator.next();
58             try {
59                 currentOp = currentOp.getChild(currentArg);
60             } catch (DataNormalizationException e) {
61                 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
62             }
63             currentArguments.add(currentArg);
64             org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier currentPath = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.create(
65                     currentArguments);
66
67             getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
68         }
69     }
70
71     @Override
72     public void delete(final LogicalDatastoreType store, final InstanceIdentifier<?> path) {
73         doDelete( store, path);
74     }
75
76     @Override
77     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
78         return AbstractDataTransaction.convertToLegacyCommitFuture(submit());
79     }
80
81     @Override
82     public CheckedFuture<Void,TransactionCommitFailedException> submit() {
83         return doSubmit();
84     }
85
86     @Override
87     public boolean cancel() {
88         return doCancel();
89     }
90 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.