From cd31662a96c12be1539ca7092bc22bd69b564a63 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Sat, 22 Aug 2015 04:42:35 +0530 Subject: [PATCH] Fixing transactional anomalies found in PolicyManagerImpl --- .../policy/mgt/core/mgt/impl/MonitoringManagerImpl.java | 7 ++++--- .../carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java | 3 +-- 2 files changed, 5 insertions(+), 5 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 a4b088e596..3b68e5b548 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 @@ -106,17 +106,17 @@ public class MonitoringManagerImpl implements MonitoringManager { PolicyManagementDAOFactory.closeConnection(); } - PolicyManagementDAOFactory.beginTransaction(); //This was added because update query below that did not return the update table primary key. if (!complianceFeatures.isEmpty()) { - + PolicyManagementDAOFactory.beginTransaction(); monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId()); if (log.isDebugEnabled()) { log.debug("Compliance status primary key " + complianceData.getId()); } // complianceData.setId(cmf.getId()); monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(), complianceFeatures); + PolicyManagementDAOFactory.commitTransaction(); complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData); List profileFeatures = policy.getProfile().getProfileFeaturesList(); for (ComplianceFeature compFeature : complianceFeatures) { @@ -127,11 +127,12 @@ public class MonitoringManagerImpl implements MonitoringManager { } } } else { + PolicyManagementDAOFactory.beginTransaction(); monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId()); //complianceData.setId(cmf.getId()); monitoringDAO.deleteNoneComplianceData(complianceData.getId()); + PolicyManagementDAOFactory.commitTransaction(); } - PolicyManagementDAOFactory.commitTransaction(); } else { if (log.isDebugEnabled()) { log.debug("There is no policy applied to this device, hence compliance monitoring was not called."); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 19658c340f..7456d57a8c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -765,12 +765,11 @@ public class PolicyManagerImpl implements PolicyManager { public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { Policy policy; try { - PolicyManagementDAOFactory.openConnection(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); Device device = service.getDevice(deviceIdentifier); //int policyId = policyDAO.getAppliedPolicyId(device.getId()); + PolicyManagementDAOFactory.openConnection(); policy = policyDAO.getAppliedPolicy(device.getId()); - } catch (DeviceManagementException e) { throw new PolicyManagementException("Error occurred while getting device id.", e); } catch (PolicyManagerDAOException e) {