Fix performance issues in sql query

custom-propery-search
Pramila Niroshan 1 year ago
parent 822f9134e2
commit 1cc4480cd9

@ -177,7 +177,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
request.addCustomProperty(propertyName, propertyValue);
}
} catch (IOException e) {
String msg = "Error Adding custom property to the paginationRequest object";
String msg = "Error occurred while converting custom property string to a Java Map";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

@ -100,11 +100,11 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
"INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID " +
"WHERE ";
if (serial != null) {
sql += "EXISTS ( " +
sql += "EXISTS (" +
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ? ) ";
isSerialProvided = true;
}
@ -112,18 +112,18 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
boolean firstCondition = true;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
if (!firstCondition) {
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 ? )";
conditionCount++;
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = '" + entry.getKey() + "' " +
"AND di.VALUE_FIELD LIKE ? ) ";
firstCondition = false;
}
}
sql += "AND d.TENANT_ID = ? ";
@ -732,9 +732,9 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
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 ?)";
"WHERE di.DEVICE_ID = d1.DEVICE_ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ?) ";
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {

@ -104,8 +104,8 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
sql += "EXISTS (" +
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ? ) ";
isSerialProvided = true;
}
@ -113,18 +113,18 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
boolean firstCondition = true;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
if (!firstCondition) {
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() + "' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = '" + entry.getKey() + "' " +
"AND di.VALUE_FIELD LIKE ? ) ";
conditionCount++;
firstCondition = false;
}
}
sql += "AND d.TENANT_ID = ? ";
@ -562,9 +562,9 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
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 ?)";
"WHERE di.DEVICE_ID = d1.DEVICE_ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ?) ";
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {

@ -103,8 +103,8 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
sql += "EXISTS (" +
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ? ) ";
isSerialProvided = true;
}
@ -112,18 +112,18 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
boolean firstCondition = true;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
if (!firstCondition) {
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() + "' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = '" + entry.getKey() + "' " +
"AND di.VALUE_FIELD LIKE ? ) ";
conditionCount++;
firstCondition = false;
}
}
sql += "AND d.TENANT_ID = ? ";
@ -542,9 +542,9 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
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 ?)";
"WHERE di.DEVICE_ID = d1.DEVICE_ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ?) ";
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {

@ -105,8 +105,8 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
sql += "EXISTS (" +
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ? ) ";
isSerialProvided = true;
}
@ -114,18 +114,18 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
boolean firstCondition = true;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
if (!firstCondition) {
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() + "' " +
"WHERE di.DEVICE_ID = d.ID " +
"AND di.KEY_FIELD = '" + entry.getKey() + "' " +
"AND di.VALUE_FIELD LIKE ? ) ";
conditionCount++;
firstCondition = false;
}
}
sql += "AND d.TENANT_ID = ? ";
@ -562,9 +562,9 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
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 ?)";
"WHERE di.DEVICE_ID = d1.DEVICE_ID " +
"AND di.KEY_FIELD = 'serial' " +
"AND di.VALUE_FIELD LIKE ?) ";
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {

Loading…
Cancel
Save