Fixing the device search issues

revert-70aa11f8
geethkokila 9 years ago
parent 220a34faa9
commit d6501cbf8c

@ -228,7 +228,8 @@ public class SearchDAOImpl implements SearchDAO {
conn = this.getConnection(); conn = this.getConnection();
String query = "SELECT * FROM DM_DEVICE_INFO WHERE DEVICE_ID IN (?) ORDER BY DEVICE_ID ;"; String query = "SELECT * FROM DM_DEVICE_INFO WHERE DEVICE_ID IN (?) ORDER BY DEVICE_ID ;";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
if (conn.getMetaData().getDatabaseProductName().contains("H2")) { if (conn.getMetaData().getDatabaseProductName().contains("H2") ||
conn.getMetaData().getDatabaseProductName().contains("MySQL")) {
String inData = Utils.getDeviceIdsAsString(devices); String inData = Utils.getDeviceIdsAsString(devices);
stmt.setString(1, inData); stmt.setString(1, inData);
} else { } else {
@ -252,7 +253,7 @@ public class SearchDAOImpl implements SearchDAO {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); throw new SearchDAOException("Error occurred while retrieving the device properties.", e);
} }
return devices; return devices;
} }

@ -112,11 +112,11 @@ public class QueryBuilderImpl implements QueryBuilder {
String querySuffix = ""; String querySuffix = "";
for (Condition con : conditions) { for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (Utils.checkDeviceDetailsColumns(con.getKey().toLowerCase())) {
querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey().toLowerCase()) +
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); con.getOperator() + Utils.getConvertedValue(con.getKey().toLowerCase(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) { } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) {
querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) +
con.getOperator() + con.getValue(); con.getOperator() + con.getValue();
} }
} }
@ -130,11 +130,11 @@ public class QueryBuilderImpl implements QueryBuilder {
String querySuffix = ""; String querySuffix = "";
for (Condition con : conditions) { for (Condition con : conditions) {
if (Utils.checkDeviceDetailsColumns(con.getKey())) { if (Utils.checkDeviceDetailsColumns(con.getKey().toLowerCase())) {
querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey().toLowerCase()) +
con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue());
} else if (Utils.checkDeviceLocationColumns(con.getKey())) { } else if (Utils.checkDeviceLocationColumns(con.getKey().toLowerCase())) {
querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey().toLowerCase()) +
con.getOperator() + con.getValue(); con.getOperator() + con.getValue();
} }
} }
@ -196,9 +196,11 @@ public class QueryBuilderImpl implements QueryBuilder {
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP " + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP \n" +
"FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + "FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" +
"DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" +
"INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" +
"WHERE D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -213,10 +215,12 @@ public class QueryBuilderImpl implements QueryBuilder {
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, " + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, DI.KEY_FIELD, DI.VALUE_FIELD \n" +
"DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + "FROM DM_DEVICE_DETAIL AS DD INNER JOIN DM_DEVICE AS D ON D.ID=DD.DEVICE_ID\n" +
"DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" + "LEFT JOIN DM_DEVICE_LOCATION AS DL ON DL.DEVICE_ID=D.ID \n" +
"DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + "INNER JOIN DM_DEVICE_TYPE AS DT ON DT.ID=D.DEVICE_TYPE_ID\n" +
"LEFT JOIN DM_DEVICE_INFO AS DI ON DI.DEVICE_ID=D.ID\n" +
"WHERE D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} }

Loading…
Cancel
Save