From 552015e6f0d3293bcd278925f1fce504c2d71892 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 15:24:58 +0530 Subject: [PATCH 1/3] Fix device delete issue --- .../core/dao/impl/AbstractDeviceDAOImpl.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 d9b7d49542..d8e32ee294 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 @@ -2397,8 +2397,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { */ private void removeDeviceOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { - String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; try { + deleteLargePayloadRecords(conn, enrollmentIds); + String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; if (!executeBatchOperation(conn, sql, enrollmentIds)) { String msg = "Failed to remove device operation response of devices with enrollmentIds : " + enrollmentIds + " while executing batch operation"; @@ -2413,6 +2414,29 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } + private void deleteLargePayloadRecords(Connection conn, List enrollmentIds) + throws DeviceManagementDAOException { + String sql = "DELETE DM_DEVICE_OPERATION_RESPONSE_LARGE " + + "FROM DM_DEVICE_OPERATION_RESPONSE_LARGE " + + "INNER JOIN DM_DEVICE_OPERATION_RESPONSE ON DM_DEVICE_OPERATION_RESPONSE_LARGE.ID = " + + "DM_DEVICE_OPERATION_RESPONSE.ID " + + "WHERE ENROLMENT_ID = ?"; + try { + if (!executeBatchOperation(conn, sql, enrollmentIds)) { + String msg = "Failed to remove device large operation response of devices with " + + "enrollmentIds : " + + enrollmentIds + " while executing batch operation"; + log.error(msg); + throw new DeviceManagementDAOException(msg); + } + } catch (SQLException e) { + String msg = "SQL error occurred while removing large device operation response of " + + "devices with enrollmentIds : " + enrollmentIds; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } + } + /*** * This method removes records of a given list of enrollments from the DM_ENROLMENT_OP_MAPPING table * @param conn Connection object From 60d67c9fea99f79abafe528610dcfe3186a261ce Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 17:57:40 +0530 Subject: [PATCH 2/3] Change method calling order --- .../carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d8e32ee294..786ee0b58a 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 @@ -1912,6 +1912,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { removeEnrollmentDeviceDetail(conn, enrollmentIds); removeEnrollmentDeviceLocation(conn, enrollmentIds); removeEnrollmentDeviceInfo(conn, enrollmentIds); + deleteLargePayloadRecords(conn, enrollmentIds); removeDeviceOperationResponse(conn, enrollmentIds); removeEnrollmentOperationMapping(conn, enrollmentIds); if (log.isDebugEnabled()) { @@ -2398,7 +2399,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { private void removeDeviceOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { try { - deleteLargePayloadRecords(conn, enrollmentIds); String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; if (!executeBatchOperation(conn, sql, enrollmentIds)) { String msg = "Failed to remove device operation response of devices with enrollmentIds : " From 35baf7ca9591094dfaf399cd9e6ae1ccd3e1f26e Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 18:14:16 +0530 Subject: [PATCH 3/3] Add log records for large response delete --- .../device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 786ee0b58a..1c6ebebae3 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 @@ -1912,13 +1912,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { removeEnrollmentDeviceDetail(conn, enrollmentIds); removeEnrollmentDeviceLocation(conn, enrollmentIds); removeEnrollmentDeviceInfo(conn, enrollmentIds); - deleteLargePayloadRecords(conn, enrollmentIds); + removeDeviceLargeOperationResponse(conn, enrollmentIds); removeDeviceOperationResponse(conn, enrollmentIds); removeEnrollmentOperationMapping(conn, enrollmentIds); if (log.isDebugEnabled()) { log.debug("Successfully removed enrollment device details, enrollment device location," + "enrollment device info, enrollment device application mapping, " + - "enrollment device operation response, enrollment operation mapping data of " + + "enrollment device operation large response, enrollment device " + + "operation response, enrollment operation mapping data of " + "devices with identifiers: " + deviceIdentifiers); } removeDeviceEnrollment(conn, deviceIds); @@ -2414,7 +2415,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - private void deleteLargePayloadRecords(Connection conn, List enrollmentIds) + private void removeDeviceLargeOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { String sql = "DELETE DM_DEVICE_OPERATION_RESPONSE_LARGE " + "FROM DM_DEVICE_OPERATION_RESPONSE_LARGE " +