From 9661502524d209015af9591ef370939fff482115 Mon Sep 17 00:00:00 2001
From: inosh-perera <inoshperera@gmail.com>
Date: Thu, 31 Mar 2016 20:08:20 +0530
Subject: [PATCH] fixing issue with certificate delete

---
 .../service/CertificateManagementServiceImpl.java    | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java
index a69cde8079f..7157d08e6b2 100644
--- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java
+++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java
@@ -17,6 +17,7 @@
  */
 package org.wso2.carbon.certificate.mgt.core.service;
 
+import com.sun.org.apache.xpath.internal.operations.Bool;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.bouncycastle.pkcs.PKCS10CertificationRequest;
@@ -31,6 +32,7 @@ import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
 import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
 import org.wso2.carbon.device.mgt.common.PaginationRequest;
 import org.wso2.carbon.device.mgt.common.PaginationResult;
+import org.wso2.carbon.device.mgt.common.TransactionManagementException;
 import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
 
 import java.io.InputStream;
@@ -165,11 +167,13 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
     @Override
     public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException {
         try {
-            CertificateManagementDAOFactory.openConnection();
+            CertificateManagementDAOFactory.beginTransaction();
             CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
-            return certificateDAO.removeCertificate(serialNumber);
-        } catch (SQLException e) {
-            String errorMsg = "Error when opening connection";
+            Boolean status = certificateDAO.removeCertificate(serialNumber);
+            CertificateManagementDAOFactory.commitTransaction();
+            return status;
+        } catch (TransactionManagementException e) {
+            String errorMsg = "Error when deleting";
             log.error(errorMsg, e);
             throw new CertificateManagementDAOException(errorMsg, e);
         } finally {