From f9bcb808f96cef3d67e2d77cda71606c0d53a443 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Wed, 30 Sep 2020 15:01:56 +0530 Subject: [PATCH] Improve device location history getting and storing functionalities --- .../carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 3 ++- .../device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 2 -- .../core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java | 2 +- 3 files changed, 3 insertions(+), 4 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 a23346ac39..fa4d731b46 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 @@ -1851,7 +1851,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { + "WHERE " + "DEVICE_ID_NAME = ? AND " + "DEVICE_TYPE_NAME = ? AND " - + "TIMESTAMP BETWEEN ? AND ?"; + + "TIMESTAMP BETWEEN ? AND ? " + + "ORDER BY timestamp"; try { Connection conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { 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 f4bda81221..63df06538d 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 @@ -30,8 +30,6 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.impl.AbstractDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.core.geo.GeoCluster; -import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; import org.wso2.carbon.device.mgt.core.report.mgt.Constants; import java.sql.Connection; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index 126079c0e4..d192f3c55b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -447,7 +447,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(6, location.getLongitude()); stmt.setFloat(7, location.getSpeed()); stmt.setFloat(8, location.getBearing()); - stmt.setLong(9, System.currentTimeMillis()); + stmt.setLong(9, location.getUpdatedTime().getTime()); stmt.setString(10, GeoHashGenerator.encodeGeohash(location)); stmt.setString(11, device.getEnrolmentInfo().getOwner()); stmt.setDouble(12, location.getAltitude());