2 * Copyright (c) 2015 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.mdsal.dom.spi.store;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction.TransactionClosePrototype;
15 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
16 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
19 * Public utility class for instantiating snapshot-backed transactions.
22 public final class SnapshotBackedTransactions {
23 private SnapshotBackedTransactions() {
28 * Creates a new read-only transaction.
30 * @param identifier Transaction Identifier
31 * @param debug Enable transaction debugging
32 * @param snapshot Snapshot which will be modified.
33 * @return A new read-only transaction
35 public static <T> @NonNull SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier,
36 final boolean debug, final DataTreeSnapshot snapshot) {
37 return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, null);
41 * Creates a new read-only transaction.
43 * @param identifier Transaction Identifier
44 * @param debug Enable transaction debugging
45 * @param snapshot Snapshot which will be modified.
46 * @param closeImpl Implementation of close method
47 * @return A new read-only transaction
49 public static <T> @NonNull SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier,
50 final boolean debug, final DataTreeSnapshot snapshot, final TransactionClosePrototype<T> closeImpl) {
51 return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, requireNonNull(closeImpl));
55 * Creates a new read-write transaction.
57 * @param identifier transaction Identifier
58 * @param debug Enable transaction debugging
59 * @param snapshot Snapshot which will be modified.
60 * @param readyImpl Implementation of ready method.
61 * @return A new read-write transaction
63 public static <T> @NonNull SnapshotBackedReadWriteTransaction<T> newReadWriteTransaction(final T identifier,
64 final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
65 return new SnapshotBackedReadWriteTransaction<>(identifier, debug, snapshot, readyImpl);
69 * Creates a new write-only transaction.
71 * @param identifier transaction Identifier
72 * @param debug Enable transaction debugging
73 * @param snapshot Snapshot which will be modified.
74 * @param readyImpl Implementation of ready method.
75 * @return A new write transaction
77 public static <T> @NonNull SnapshotBackedWriteTransaction<T> newWriteTransaction(final T identifier,
78 final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
79 return new SnapshotBackedWriteTransaction<>(identifier, debug, snapshot, readyImpl);