Reorganize transactionChainHandler usage.
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / PatchDataTransactionUtil.java
index 6a47e7051bed4e3c83c922c969724e7615c01f99..d92f143a1458c20d58731e5f56250185229c8a30 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadOperations;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
@@ -46,7 +47,8 @@ public final class PatchDataTransactionUtil {
     }
 
     /**
-     * Process edit operations of one {@link PatchContext}.
+     * Process edit operations of one {@link PatchContext}. Close {@link DOMTransactionChain} inside of object
+     * {@link TransactionVarsWrapper} provided as a parameter.
      * @param context Patch context to be processed
      * @param transactionNode Wrapper for transaction
      * @param schemaContextRef Soft reference for global schema context
@@ -56,7 +58,8 @@ public final class PatchDataTransactionUtil {
                                                final SchemaContextRef schemaContextRef) {
         final List<PatchStatusEntity> editCollection = new ArrayList<>();
         boolean noError = true;
-        final DOMDataTreeReadWriteTransaction tx = transactionNode.getTransactionChain().newReadWriteTransaction();
+        final DOMTransactionChain transactionChain = transactionNode.getTransactionChain();
+        final DOMDataTreeReadWriteTransaction tx = transactionChain.newReadWriteTransaction();
 
         for (final PatchEntity patchEntity : context.getData()) {
             if (noError) {
@@ -134,7 +137,8 @@ public final class PatchDataTransactionUtil {
             final FluentFuture<? extends CommitInfo> future = tx.commit();
 
             try {
-                FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
+                //This method will close transactionChain
+                FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response, transactionChain);
             } catch (final RestconfDocumentedException e) {
                 // if errors occurred during transaction commit then patch failed and global errors are reported
                 return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), false,
@@ -144,7 +148,7 @@ public final class PatchDataTransactionUtil {
             return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
         } else {
             tx.cancel();
-            transactionNode.getTransactionChainHandler().reset();
+            transactionChain.close();
             return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection),
                     false, null);
         }
@@ -155,7 +159,7 @@ public final class PatchDataTransactionUtil {
      * @param dataStore Datastore to write data to
      * @param path Path for data to be created
      * @param payload Data to be created
-     * @param rWTransaction Transaction
+     * @param rwTransaction Transaction
      * @param schemaContextRef Soft reference for global schema context
      */
     private static void createDataWithinTransaction(final LogicalDatastoreType dataStore,