X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Frests%2Futils%2FDeleteDataTransactionUtil.java;h=9544a07f3a592c2cfa69384d002856f199d702d2;hb=refs%2Fchanges%2F71%2F90371%2F30;hp=25d8de9902121112c58281fe0be19f560c1b96b5;hpb=4ad8c8f798f194cc2c21212d8e5f0934d1a25306;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java index 25d8de9902..9544a07f3a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java @@ -7,19 +7,16 @@ */ package org.opendaylight.restconf.nb.rfc8040.rests.utils; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; -import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; -import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; /** * Util class for delete specific data in config DS. - * */ public final class DeleteDataTransactionUtil { @@ -30,36 +27,20 @@ public final class DeleteDataTransactionUtil { /** * Delete data from DS via transaction. * - * @param transactionNode - * Wrapper for data of transaction + * @param strategy object that perform the actual DS operations * @return {@link Response} */ - public static Response deleteData(final TransactionVarsWrapper transactionNode) { - final CheckedFuture future = submitData( - transactionNode.getTransactionChainHandler(), - transactionNode.getInstanceIdentifier().getInstanceIdentifier()); + public static Response deleteData(final RestconfStrategy strategy) { + strategy.prepareReadWriteExecution(); + final YangInstanceIdentifier path = strategy.getInstanceIdentifier().getInstanceIdentifier(); + TransactionUtil.checkItemExists(strategy, LogicalDatastoreType.CONFIGURATION, path, + RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE); + strategy.delete(LogicalDatastoreType.CONFIGURATION, path); + final FluentFuture future = strategy.commit(); final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT); - FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response); + //This method will close transactionChain if any + FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response, + strategy.getTransactionChain()); return response.build(); } - - /** - * Delete data via transaction. Return error if data to delete does not exist. - * - * @param transactionChainHandler - * transaction chain handler - * @param readWriteTx - * read and write transaction - * @param path - * path of data to delete - * @return {@link CheckedFuture} - */ - private static CheckedFuture submitData( - final TransactionChainHandler transactionChainHandler, final YangInstanceIdentifier path) { - final DOMDataReadWriteTransaction readWriteTx = transactionChainHandler.get().newReadWriteTransaction(); - TransactionUtil.checkItemExists(transactionChainHandler, readWriteTx, LogicalDatastoreType.CONFIGURATION, path, - RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE); - readWriteTx.delete(LogicalDatastoreType.CONFIGURATION, path); - return readWriteTx.submit(); - } }