diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/Constants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/Constants.java index 71eaf20a5f..68111a5159 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/Constants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/common/Constants.java @@ -21,6 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.core.common; public class Constants { public static final String SCHEME_SEPARATOR = "://"; public static final String COLON = ":"; + public static final String QUERY_WILDCARD = "%"; public static final String URI_QUERY_SEPARATOR = "?"; public static final String URI_SEPARATOR = "/"; public static final String BASIC_AUTH_HEADER_PREFIX = "Basic "; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java index fb3ad85549..30655aa1e4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -17,6 +17,7 @@ */ package io.entgra.device.mgt.core.device.mgt.core.dao.impl; +import io.entgra.device.mgt.core.device.mgt.core.common.Constants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; @@ -298,9 +299,13 @@ public class ApplicationDAOImpl implements ApplicationDAO { String filter = request.getFilter(); if (filter != null) { sql = sql + "AND NAME LIKE ? "; + filter = Constants.QUERY_WILDCARD.concat(filter).concat(Constants.QUERY_WILDCARD); } + + boolean isLimitPresent = false; if (request != null && request.getRowCount() != -1) { sql = sql + "LIMIT ? OFFSET ?"; + isLimitPresent = true; } Connection conn = this.getConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -312,7 +317,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { if (filter != null){ stmt.setString(paramIdx++, filter); } - if (request != null && request.getRowCount() != -1) { + if (isLimitPresent) { stmt.setInt(paramIdx++, request.getRowCount()); stmt.setInt(paramIdx, request.getStartIndex()); } diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index ce963d1437..b0de3dc590 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -463,6 +463,8 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( )ENGINE = InnoDB; CREATE INDEX IDX_DM_APPLICATION ON DM_APPLICATION(DEVICE_ID, ENROLMENT_ID, TENANT_ID); +CREATE INDEX DM_APPLICATION_NAME ON DM_APPLICATION(NAME); +CREATE INDEX DM_APPLICATION_NAME_PLATFORM_TID ON DM_APPLICATION(NAME, PLATFORM, TENANT_ID); -- END OF POLICY RELATED TABLES --