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/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java index bb7318adde..7c2cfad05c 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/device/GenericDeviceDAOImpl.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/device/GenericDeviceDAOImpl.java @@ -95,10 +95,17 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { //Filter by serial number or any Custom Property in DM_DEVICE_INFO if (serial != null || !request.getCustomProperty().isEmpty()) { - sql = sql + "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID WHERE "; + sql = sql + + "FROM DM_DEVICE d " + + "INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " + + "WHERE "; if (serial != null) { - sql += "EXISTS ( SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d.ID "; - sql += "AND di.KEY_FIELD = 'serial' AND di.VALUE_FIELD LIKE ? ) "; + sql += "EXISTS ( " + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d.ID "; + sql += "AND di.KEY_FIELD = 'serial' " + + "AND di.VALUE_FIELD LIKE ? ) "; isSerialProvided = true; } if (!request.getCustomProperty().isEmpty()) { @@ -110,14 +117,17 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { if (conditionCount > 0) { sql += "AND "; } - sql += "EXISTS ( SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d.ID "; - sql += "AND di.KEY_FIELD = '"+entry.getKey()+"' AND di.VALUE_FIELD LIKE ? ) "; + sql += "EXISTS (" + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d.ID "; + sql += "AND di.KEY_FIELD = '" + entry.getKey() + "' " + + "AND di.VALUE_FIELD LIKE ? )"; conditionCount++; } } sql += "AND d.TENANT_ID = ? "; - } - else { + } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? "; } //Add query for last updated timestamp @@ -719,8 +729,12 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { //Filter Group with serial number or any Custom Property in DM_DEVICE_INFO if (serial != null || !request.getCustomProperty().isEmpty()) { if (serial != null) { - sql += "AND EXISTS (SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d1.DEVICE_ID "; - sql += "AND di.KEY_FIELD = 'serial' AND di.VALUE_FIELD LIKE ?)"; + sql += "AND EXISTS (" + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d1.DEVICE_ID "; + sql += "AND di.KEY_FIELD = 'serial' " + + "AND di.VALUE_FIELD LIKE ?)"; isSerialProvided = true; } if (!request.getCustomProperty().isEmpty()) { 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/device/SQLServerDeviceDAOImpl.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/device/SQLServerDeviceDAOImpl.java index 604fd3f268..39ecef6c67 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/device/SQLServerDeviceDAOImpl.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/device/SQLServerDeviceDAOImpl.java @@ -97,10 +97,17 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { //Filter by serial number or any Custom Property in DM_DEVICE_INFO if (serial != null || !request.getCustomProperty().isEmpty()) { - sql = sql + "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID WHERE "; + sql = sql + + "FROM DM_DEVICE d " + + "INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " + + "WHERE "; if (serial != null) { - sql += "EXISTS ( SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d.ID "; - sql += "AND di.KEY_FIELD = 'serial' AND di.VALUE_FIELD LIKE ? ) "; + sql += "EXISTS (" + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d.ID "; + sql += "AND di.KEY_FIELD = 'serial' " + + "AND di.VALUE_FIELD LIKE ? ) "; isSerialProvided = true; } if (!request.getCustomProperty().isEmpty()) { @@ -112,14 +119,17 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { if (conditionCount > 0) { sql += "AND "; } - sql += "EXISTS ( SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d.ID "; - sql += "AND di.KEY_FIELD = '"+entry.getKey()+"' AND di.VALUE_FIELD LIKE ? ) "; + sql += "EXISTS (" + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d.ID "; + sql += "AND di.KEY_FIELD = '" + entry.getKey() + "' " + + "AND di.VALUE_FIELD LIKE ? ) "; conditionCount++; } } sql += "AND d.TENANT_ID = ? "; - } - else { + } else { sql = sql + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? "; } //Add query for last updated timestamp @@ -549,8 +559,12 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl { //Filter Group with serial number or any Custom Property in DM_DEVICE_INFO if (serial != null || !request.getCustomProperty().isEmpty()) { if (serial != null) { - sql += "AND EXISTS (SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d1.DEVICE_ID "; - sql += "AND di.KEY_FIELD = 'serial' AND di.VALUE_FIELD LIKE ?)"; + sql += "AND EXISTS (" + + "SELECT VALUE_FIELD " + + "FROM DM_DEVICE_INFO di " + + "WHERE di.DEVICE_ID = d1.DEVICE_ID "; + sql += "AND di.KEY_FIELD = 'serial' " + + "AND di.VALUE_FIELD LIKE ?)"; isSerialProvided = true; } if (!request.getCustomProperty().isEmpty()) {