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
index 4efd98e78dd8b24c13ab43df05af81612fecabdc..85e9fc2870af393b7d1bdc7b0914b2f8a56e91fc 100644 (file)
@@ -7,10 +7,13 @@
  */
 package org.opendaylight.mdsal.dom.spi.store;
 
-import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction.TransactionClosePrototype;
+import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
 
 /**
  * Public utility class for instantiating snapshot-backed transactions.
@@ -18,7 +21,20 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
 @Beta
 public final class SnapshotBackedTransactions {
     private SnapshotBackedTransactions() {
-        throw new UnsupportedOperationException("Utility class");
+        // Hidden on purpose
+    }
+
+    /**
+     * Creates a new read-only transaction.
+     *
+     * @param identifier Transaction Identifier
+     * @param debug Enable transaction debugging
+     * @param snapshot Snapshot which will be modified.
+     * @return A new read-only transaction
+     */
+    public static <T> @NonNull SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier,
+            final boolean debug, final DataTreeSnapshot snapshot) {
+        return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, null);
     }
 
     /**
@@ -27,9 +43,12 @@ public final class SnapshotBackedTransactions {
      * @param identifier Transaction Identifier
      * @param debug Enable transaction debugging
      * @param snapshot Snapshot which will be modified.
+     * @param closeImpl Implementation of close method
+     * @return A new read-only transaction
      */
-    public static <T> SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier, final boolean debug, final DataTreeSnapshot snapshot) {
-        return new SnapshotBackedReadTransaction<T>(identifier, debug, snapshot);
+    public static <T> @NonNull SnapshotBackedReadTransaction<T> newReadTransaction(final T identifier,
+            final boolean debug, final DataTreeSnapshot snapshot, final TransactionClosePrototype<T> closeImpl) {
+        return new SnapshotBackedReadTransaction<>(identifier, debug, snapshot, requireNonNull(closeImpl));
     }
 
     /**
@@ -39,10 +58,11 @@ public final class SnapshotBackedTransactions {
      * @param debug Enable transaction debugging
      * @param snapshot Snapshot which will be modified.
      * @param readyImpl Implementation of ready method.
+     * @return A new read-write transaction
      */
-    public static <T> SnapshotBackedReadWriteTransaction<T> newReadWriteTransaction(final T identifier, final boolean debug,
-            final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
-        return new SnapshotBackedReadWriteTransaction<T>(identifier, debug, snapshot, readyImpl);
+    public static <T> @NonNull SnapshotBackedReadWriteTransaction<T> newReadWriteTransaction(final T identifier,
+            final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
+        return new SnapshotBackedReadWriteTransaction<>(identifier, debug, snapshot, readyImpl);
     }
 
     /**
@@ -52,9 +72,10 @@ public final class SnapshotBackedTransactions {
      * @param debug Enable transaction debugging
      * @param snapshot Snapshot which will be modified.
      * @param readyImpl Implementation of ready method.
+     * @return A new write transaction
      */
-    public static <T> SnapshotBackedWriteTransaction<T> newWriteTransaction(final T identifier, final boolean debug,
-            final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
-        return new SnapshotBackedWriteTransaction<T>(identifier, debug, snapshot, readyImpl);
+    public static <T> @NonNull SnapshotBackedWriteTransaction<T> newWriteTransaction(final T identifier,
+            final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) {
+        return new SnapshotBackedWriteTransaction<>(identifier, debug, snapshot, readyImpl);
     }
 }