From 9280810b2402eda3da857489466643cfed4e6e61 Mon Sep 17 00:00:00 2001 From: charitha Date: Mon, 18 May 2020 10:11:25 +0530 Subject: [PATCH] Avoid unnecessary db connection --- .../core/mgt/impl/MonitoringManagerImpl.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 1edca6715c..351da8495e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -289,20 +289,20 @@ public class MonitoringManagerImpl implements MonitoringManager { PolicyManagementDAOFactory.closeConnection(); } - try { - PolicyManagementDAOFactory.beginTransaction(); - if (!firstTimeComplianceData.isEmpty()) { + if (!firstTimeComplianceData.isEmpty()) { + try { + PolicyManagementDAOFactory.beginTransaction(); monitoringDAO.addComplianceDetails(firstTimeComplianceData); PolicyManagementDAOFactory.commitTransaction(); + } catch (MonitoringDAOException e) { + PolicyManagementDAOFactory.rollbackTransaction(); + throw new PolicyComplianceException("Error occurred from monitoring dao.", e); + } catch (PolicyManagerDAOException e) { + PolicyManagementDAOFactory.rollbackTransaction(); + throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e); + } finally { + PolicyManagementDAOFactory.closeConnection(); } - } catch (MonitoringDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new PolicyComplianceException("Error occurred from monitoring dao.", e); - } catch (PolicyManagerDAOException e) { - PolicyManagementDAOFactory.rollbackTransaction(); - throw new PolicyComplianceException("Error occurred reading the applied policies to devices.", e); - } finally { - PolicyManagementDAOFactory.closeConnection(); } if (!notifiableDeviceEnrollments.isEmpty()) {