Merge pull request 'Refactor SQL query to filter out 'REMOVED' and 'DELETED' statuses' (#393) from pramilaniroshan/device-mgt-core:rm-11025 into master

Reviewed-on: community/device-mgt-core#393
apps-11010
Pahansith Gunathilake 6 months ago
commit 3abe68788c

@ -1297,7 +1297,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
query = query.concat("WHERE DM_DEVICE.ID IN (");
StringJoiner joiner = new StringJoiner(",", query ,
") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ?");
") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ? AND e.STATUS != ?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
query = joiner.toString();
@ -1341,6 +1341,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Count;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -1078,7 +1079,7 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?");
") AND DM_DEVICE.TENANT_ID AND e.STATUS NOT IN (?, ?)");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
@ -1120,6 +1121,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}

@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Count;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceBilling;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
@ -1057,7 +1058,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?");
") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS NOT IN (?, ?)");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
@ -1099,6 +1100,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}

@ -926,7 +926,7 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
+ "INNER JOIN (SELECT ID, NAME FROM DM_DEVICE_TYPE) AS device_types ON "
+ "device_types.ID = DM_DEVICE.DEVICE_TYPE_ID "
+ "WHERE DM_DEVICE.ID IN (",
") AND DM_DEVICE.TENANT_ID = ?");
") AND DM_DEVICE.TENANT_ID = ? AND e.STATUS != ? AND e.STATUS != ?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
@ -968,6 +968,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
ps.setInt(index++, tenantId);
ps.setString(index++, EnrolmentInfo.Status.REMOVED.toString());
ps.setString(index++, EnrolmentInfo.Status.DELETED.toString());
if (isDeviceNameProvided) {
ps.setString(index++, name + "%");
}

Loading…
Cancel
Save