Convert DCL tests to use DTCL
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / AsyncWriteTransaction.java
index 79f80a3f0577e1ce2fd28486497652a982ee7381..852c4e488617a25ef339dc4d58da6d03c4101fad 100644 (file)
@@ -14,7 +14,9 @@ import com.google.common.util.concurrent.MoreExecutors;
 import javax.annotation.CheckReturnValue;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.MappingCheckedFuture;
 import org.opendaylight.yangtools.concepts.Path;
+import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
 
 /**
  * Write transaction provides mutation capabilities for a data tree.
@@ -157,8 +159,7 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * ({@link AsyncConfigurationCommitHandler}) if the transaction changes the data tree.
      *
      * <p>
-     * The effects of a successful commit of data depends on data change listeners
-     * ({@link AsyncDataChangeListener}) and commit participants
+     * The effects of a successful commit of data depends on data tree change listeners and commit participants
      * ({@link AsyncConfigurationCommitHandler}) that are registered with the data broker.
      *
      * <h3>Example usage:</h3>
@@ -338,7 +339,11 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * @deprecated Use {@link #commit()} instead.
      */
     @Deprecated
-    CheckedFuture<Void,TransactionCommitFailedException> submit();
+    @CheckReturnValue
+    default CheckedFuture<Void, TransactionCommitFailedException> submit() {
+        return MappingCheckedFuture.create(commit().transform(ignored -> null, MoreExecutors.directExecutor()),
+                SUBMIT_EXCEPTION_MAPPER);
+    }
 
     /**
      * Submits this transaction to be asynchronously applied to update the logical data tree. The returned
@@ -370,8 +375,17 @@ public interface AsyncWriteTransaction<P extends Path<P>, D> extends AsyncTransa
      * @throws IllegalStateException if the transaction is already committed or was canceled.
      */
     @CheckReturnValue
-    default @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
-        return FluentFuture.from(submit()).transformAsync(ignored -> CommitInfo.emptyFluentFuture(),
-            MoreExecutors.directExecutor());
-    }
+    @NonNull FluentFuture<? extends @NonNull CommitInfo> commit();
+
+    /**
+     * This only exists for reuse by the deprecated {@link #submit} method and is not intended for general use.
+     */
+    @Deprecated
+    ExceptionMapper<TransactionCommitFailedException> SUBMIT_EXCEPTION_MAPPER =
+        new ExceptionMapper<TransactionCommitFailedException>("submit", TransactionCommitFailedException.class) {
+            @Override
+            protected TransactionCommitFailedException newWithCause(String message, Throwable cause) {
+                return new TransactionCommitFailedException(message, cause);
+            }
+        };
 }