From 0aee974b3519751ba81c08a78abce9997cbf1516 Mon Sep 17 00:00:00 2001 From: Amanda <74random.amanda@gmail.com> Date: Tue, 8 Oct 2019 17:33:24 +0530 Subject: [PATCH] Fix issue in retrieving IoTS devices --- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 3ab5e2f6f6..55a7a345ee 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 @@ -163,16 +163,20 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { + "d.NAME, " + "t.NAME AS DEVICE_TYPE, " + "d.DEVICE_IDENTIFICATION " - + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " - + "WHERE " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t"; + + if (deviceData.getLastModifiedDate() != null) { + sql += ", DM_DEVICE_DETAIL dt"; + } + + sql += " WHERE " + "t.NAME = ? AND " + "t.ID = d.DEVICE_TYPE_ID AND " + "d.DEVICE_IDENTIFICATION = ? AND " - + "d.TENANT_ID = ? AND " - + "dt.DEVICE_ID = d.ID"; + + "d.TENANT_ID = ?"; if (deviceData.getLastModifiedDate() != null) { - sql += " AND dt.UPDATE_TIMESTAMP > ?"; + sql += " AND dt.DEVICE_ID = d.ID AND dt.UPDATE_TIMESTAMP > ?"; } sql += ") d1 WHERE d1.ID = e.DEVICE_ID AND ";