2 * Copyright (c) 2015 Inocybe 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
9 package org.opendaylight.controller.packetcable.provider;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import com.google.common.util.concurrent.CheckedFuture;
21 public class MdsalUtils {
22 private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
23 private DataBroker databroker = null;
26 * Class constructor setting the data broker.
28 * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
30 public MdsalUtils(DataBroker dataBroker) {
31 this.databroker = dataBroker;
35 * Executes delete as a blocking transaction.
37 * @param store {@link LogicalDatastoreType} which should be modified
38 * @param path {@link InstanceIdentifier} to read from
39 * @param <D> the data object type
40 * @return the result of the request
42 public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
43 final LogicalDatastoreType store, final InstanceIdentifier<D> path) {
44 boolean result = false;
45 final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
46 transaction.delete(store, path);
47 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
51 } catch (TransactionCommitFailedException e) {
52 LOG.warn("Failed to delete {} ", path, e);
58 * Executes merge as a blocking transaction.
60 * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
61 * @param path {@link InstanceIdentifier} for path to read
62 * @param <D> the data object type
63 * @return the result of the request
65 public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
66 final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data) {
67 boolean result = false;
68 final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
69 transaction.merge(logicalDatastoreType, path, data, true);
70 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
74 } catch (TransactionCommitFailedException e) {
75 LOG.warn("Failed to merge {} ", path, e);