From 739ee8281f3b71ad405df15ddae2a498e0d5bd0d Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Tue, 17 Mar 2020 09:33:40 +0000 Subject: [PATCH] Remove duplicates in getApplications API --- .../mgt/core/dao/impl/ApplicationDAOImpl.java | 18 ++++++++++++------ 1 file changed, 12 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/ApplicationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java index 894062df51c..aa44f0996a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -277,9 +277,9 @@ public class ApplicationDAOImpl implements ApplicationDAO { throws DeviceManagementDAOException { List applications = new ArrayList<>(); Application application; - String sql = "Select " + - "ID," + - " NAME, " + + String sql = "SELECT " + + "ID, " + + "NAME, " + "APP_IDENTIFIER, " + "PLATFORM, " + "CATEGORY, " + @@ -291,9 +291,15 @@ public class ApplicationDAOImpl implements ApplicationDAO { "MEMORY_USAGE, " + "IS_ACTIVE, " + "TENANT_ID " + - "From DM_APPLICATION " + - "WHERE PLATFORM = ? " + - "AND TENANT_ID = ? LIMIT ? OFFSET ?"; + "FROM DM_APPLICATION " + + "WHERE NOT EXISTS " + + "(SELECT " + + "ID " + + "FROM DM_APPLICATION A " + + "WHERE A.NAME = DM_APPLICATION.NAME " + + "AND A.ID < DM_APPLICATION.ID) " + + "AND PLATFORM = ? " + + "AND TENANT_ID = ? LIMIT ? OFFSET ?"; try { Connection conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) {