Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / AbstractReadWriteTransaction.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 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
15 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
16 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
17 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Deprecated
24 public class AbstractReadWriteTransaction extends AbstractWriteTransaction<DOMDataReadWriteTransaction> {
25
26     private static final Logger LOG = LoggerFactory.getLogger(AbstractReadWriteTransaction.class);
27
28     public AbstractReadWriteTransaction(final DOMDataReadWriteTransaction delegate,
29             final BindingToNormalizedNodeCodec codec) {
30         super(delegate, codec);
31     }
32
33     @Override
34     protected final void ensureParentsByMerge(final LogicalDatastoreType store,
35             final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier normalizedPath,
36             final InstanceIdentifier<?> path) {
37         List<PathArgument> currentArguments = new ArrayList<>();
38         DataNormalizationOperation<?> currentOp = getCodec().getDataNormalizer().getRootOperation();
39         Iterator<PathArgument> iterator = normalizedPath.getPathArguments().iterator();
40         while (iterator.hasNext()) {
41             PathArgument currentArg = iterator.next();
42             try {
43                 currentOp = currentOp.getChild(currentArg);
44             } catch (DataNormalizationException e) {
45                 throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e);
46             }
47             currentArguments.add(currentArg);
48             org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier currentPath =
49                     org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.create(currentArguments);
50
51             final Boolean exists;
52             try {
53                 exists = getDelegate().exists(store, currentPath).checkedGet();
54             } catch (ReadFailedException e) {
55                 LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e);
56                 throw new IllegalStateException("Failed to read pre-existing data", e);
57             }
58
59             if (!exists && iterator.hasNext()) {
60                 getDelegate().merge(store, currentPath, currentOp.createDefault(currentArg));
61             }
62         }
63     }
64 }

©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.