diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GeofenceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GeofenceDAO.java index 8c309673676..4a7fc925a39 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GeofenceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/GeofenceDAO.java @@ -116,7 +116,7 @@ public interface GeofenceDAO { * @param groupIdsToDelete group ids to be removed from the mapping table * @throws DeviceManagementDAOException error occurred while deleting group id mapping records */ - void deleteGeofenceGroupMapping(List groupIdsToDelete) throws DeviceManagementDAOException; + void deleteGeofenceGroupMapping(List groupIdsToDelete, int fenceId) throws DeviceManagementDAOException; /** * Create geofence-event mapping records diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java index bd557dfd7f3..50264346958 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java @@ -356,13 +356,14 @@ public class GeofenceDAOImpl implements GeofenceDAO { } @Override - public void deleteGeofenceGroupMapping(List groupIdsToDelete) throws DeviceManagementDAOException { + public void deleteGeofenceGroupMapping(List groupIdsToDelete, int fenceId) throws DeviceManagementDAOException { try { Connection conn = this.getConnection(); - String sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ?"; + String sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ? AND FENCE_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { for (Integer groupId : groupIdsToDelete) { stmt.setInt(1, groupId); + stmt.setInt(2, fenceId); stmt.addBatch(); } stmt.executeBatch(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index 09f8bf0d598..9c77c755884 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -1503,7 +1503,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } List groupIdsOfGeoFence = geofenceDAO.getGroupIdsOfGeoFence(fenceId); if (!groupIdsOfGeoFence.isEmpty()) { - geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence); + geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence, fenceId); } geofenceDAO.deleteGeofenceById(fenceId); DeviceManagementDAOFactory.commitTransaction(); @@ -1554,7 +1554,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic groupIdsToAdd.add(newGroupId); } } - geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete); + geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId); geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd); DeviceManagementDAOFactory.commitTransaction(); if (updatedRowCount > 0) {