From 579d91bd79f3e305adb0d774c3bd48f858a7cb06 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 25 Aug 2016 13:10:23 +0530 Subject: [PATCH] Fix issue in get devices with since parameter. --- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 15 +++++++++++++-- .../dao/impl/device/GenericDeviceDAOImpl.java | 9 +++++---- 2 files changed, 18 insertions(+), 6 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 44bdd5ba45..6ca4378806 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 @@ -416,11 +416,13 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { boolean isOwnershipProvided = false; String status = request.getStatus(); boolean isStatusProvided = false; + Date since = request.getSince(); + boolean isSinceProvided = false; try { conn = this.getConnection(); String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DEVICE_IDENTIFICATION, " + - "t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID " + - "AND d.TENANT_ID = ?"; + "t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID"; if (deviceType != null && !deviceType.isEmpty()) { sql = sql + " AND t.NAME = ?"; @@ -432,6 +434,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { isDeviceNameProvided = true; } + //Add query for last updated timestamp + if (since != null) { + sql = sql + " AND dt.UPDATE_TIMESTAMP > ?"; + isSinceProvided = true; + } + sql = sql + ") d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?"; if (ownership != null && !ownership.isEmpty()) { @@ -458,6 +466,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } + if (isSinceProvided) { + stmt.setLong(paramIdx++, since.getTime()); + } stmt.setInt(paramIdx++, tenantId); if (isOwnershipProvided) { stmt.setString(paramIdx++, request.getOwnership()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 246a1bc1f3..2c47c600d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -59,8 +59,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; + "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " + + "WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID"; //Add the query for device-type if (deviceType != null && !deviceType.isEmpty()) { @@ -75,7 +76,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { //Add query for last updated timestamp if (since != null) { - sql = sql + " AND d.LAST_UPDATED_TIMESTAMP > ?"; + sql = sql + " AND dt.UPDATE_TIMESTAMP > ?"; isSinceProvided = true; } @@ -109,7 +110,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } if (isSinceProvided) { - stmt.setTimestamp(paramIdx++, new Timestamp(since.getTime())); + stmt.setLong(paramIdx++, since.getTime()); } stmt.setInt(paramIdx++, tenantId); if (isOwnershipProvided) {