Adopt odlparent-10.0.0/yangtools-8.0.0-SNAPSHOT
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / store / SnapshotBackedTransactions.java
1 /*
2  * Copyright (c) 2015 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.mdsal.dom.spi.store;
9
10 import static java.util.Objects.requireNonNull;
11
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;
17
18 /**
19  * Public utility class for instantiating snapshot-backed transactions.
20  */
21 @Beta
22 public final class SnapshotBackedTransactions {
23     private SnapshotBackedTransactions() {
24         // Hidden on purpose
25     }
26
27     /**
28      * Creates a new read-only transaction.
29      *
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
34      */
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);
38     }
39
40     /**
41      * Creates a new read-only transaction.
42      *
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
48      */
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));
52     }
53
54     /**
55      * Creates a new read-write transaction.
56      *
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
62      */
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);
66     }
67
68     /**
69      * Creates a new write-only transaction.
70      *
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
76      */
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);
80     }
81 }