Close transaction chain on failures 27/97127/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Aug 2021 12:37:02 +0000 (14:37 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 10 Aug 2021 12:37:02 +0000 (14:37 +0200)
If the transaction fails we end fail to close it. Fix it by using
try-with-resources.

Change-Id: I863c40903c3dba16b661aff1bda6459ba23c0997
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractNotificationsData.java

index 45dde3f2da1fce45b8e7bf3ca191508e5d9f39a8..1518bdd0127845314741bba47794d0bab811c5ab 100644 (file)
@@ -78,12 +78,12 @@ abstract class AbstractNotificationsData {
      * Delete data in DS.
      */
     protected void deleteDataInDS() throws Exception {
-        final DOMTransactionChain transactionChain = this.transactionChainHandler.get();
-        final DOMDataTreeWriteTransaction wTx = transactionChain.newWriteOnlyTransaction();
-        wTx.delete(LogicalDatastoreType.OPERATIONAL, IdentifierCodec
+        try (DOMTransactionChain transactionChain = this.transactionChainHandler.get()) {
+            final DOMDataTreeWriteTransaction wTx = transactionChain.newWriteOnlyTransaction();
+            wTx.delete(LogicalDatastoreType.OPERATIONAL, IdentifierCodec
                 .deserialize(MonitoringModule.PATH_TO_STREAM_WITHOUT_KEY + this.localName, this.schemaHandler.get()));
-        wTx.commit().get();
-        transactionChain.close();
+            wTx.commit().get();
+        }
     }
 
     /**