2 * Copyright (c) 2016 Red Hat, 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.netvirt.aclservice.tests.infra;
10 import javax.inject.Inject;
11 import org.eclipse.xtext.xbase.lib.Pair;
12 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
15 import org.opendaylight.mdsal.binding.api.WriteTransaction;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 * Utility around {@link WriteTransaction} for working with pairs and tuples of Type/Id/DataObject.
24 * <ul><li>{@link Pair}s (TODO or {@link java.util.Map.Entry} ?) of {@link InstanceIdentifier}s and
27 * {@link LogicalDatastoreType}s/InstanceIdentifiers/DataObjects
28 * <li>{@link DataTreeIdentifierDataObjectPairBuilder}
31 * @author Michael Vorburger
33 public class DataBrokerPairsUtil {
34 // TODO use, when merged, pending https://git.opendaylight.org/gerrit/#/c/46534/ (and https://git.opendaylight.org/gerrit/#/c/46479/)
36 private final SingleTransactionDataBroker singleTxDB;
39 public DataBrokerPairsUtil(DataBroker db) {
40 this.singleTxDB = new SingleTransactionDataBroker(db);
43 public <T extends DataObject> void put(LogicalDatastoreType type, Pair<InstanceIdentifier<T>, T> pair)
44 throws TransactionCommitFailedException {
45 singleTxDB.syncWrite(type, pair.getKey(), pair.getValue());
48 public <T extends DataObject> void put(Pair<DataTreeIdentifier<T>, T> pair)
49 throws TransactionCommitFailedException {
50 singleTxDB.syncWrite(pair.getKey().getDatastoreType(), pair.getKey().getRootIdentifier(), pair.getValue());
53 public <T extends DataObject> void put(DataTreeIdentifierDataObjectPairBuilder<T> builder)
54 throws TransactionCommitFailedException {