diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 8994dff8651..d3f6569faaa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1873,6 +1873,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { if (log.isDebugEnabled()) { log.debug("Successfully removed device policy data of devices: " + deviceIdentifiers); } + removeDeviceApplication(conn, deviceIds); + if (log.isDebugEnabled()) { + log.debug("Successfully removed device application data of devices: " + deviceIdentifiers); + } if (log.isDebugEnabled()) { log.debug("Starting to remove " + enrollmentIds.size() + " enrollment data of devices with " + "identifiers: " + deviceIdentifiers); @@ -2260,6 +2264,29 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } + /*** + * This method removes records of a given list of devices from the DM_APPLICATION table + * @param conn Connection object + * @param deviceIds list of device ids (primary keys) + * @throws DeviceManagementDAOException if deletion fails + */ + private void removeDeviceApplication(Connection conn, List deviceIds) + throws DeviceManagementDAOException { + String sql = "DELETE FROM DM_APPLICATION WHERE DEVICE_ID = ?"; + try { + if (!executeBatchOperation(conn, sql, deviceIds)) { + String msg = "Failed to remove applications of devices with deviceIds : " + deviceIds + + " while executing batch operation"; + log.error(msg); + throw new DeviceManagementDAOException(msg); + } + } catch (SQLException e) { + String msg = "SQL error occurred while removing applications of devices devices with deviceIds : " + deviceIds; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } + } + /*** * This method removes records of a given list of enrollments from the DM_DEVICE_DETAIL table * @param conn Connection object