Refactored SQL queries and added null checks

revert-70aa11f8
mharindu 9 years ago
parent 52b4902aa5
commit 9d8c52958d

@ -145,7 +145,7 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," + "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," +
"d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
@ -175,7 +175,7 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQueryForType = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + String selectDBQueryForType = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION," +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; "WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";

@ -229,8 +229,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); if (dmsDevice != null) {
device.setProperties(dmsDevice.getProperties()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
}
devices.add(device); devices.add(device);
} }
return devices; return devices;
@ -259,8 +261,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); if (dmsDevice != null) {
device.setProperties(dmsDevice.getProperties()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
}
devices.add(device); devices.add(device);
} }
return devices; return devices;
@ -409,8 +413,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (device != null) { if (device != null) {
DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType()); DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType());
Device pluginSpecificInfo = dms.getDevice(deviceId); Device pluginSpecificInfo = dms.getDevice(deviceId);
device.setProperties(pluginSpecificInfo.getProperties()); if (pluginSpecificInfo != null) {
device.setFeatures(pluginSpecificInfo.getFeatures()); device.setFeatures(pluginSpecificInfo.getFeatures());
device.setProperties(pluginSpecificInfo.getProperties());
}
} }
return device; return device;
} }
@ -554,8 +560,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); if (dmsDevice != null) {
device.setProperties(dmsDevice.getProperties()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
}
devices.add(device); devices.add(device);
} }
return devices; return devices;
@ -596,8 +604,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); if (dmsDevice != null) {
device.setProperties(dmsDevice.getProperties()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
}
devices.add(device); devices.add(device);
} }
} }
@ -643,8 +653,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device dmsDevice = Device dmsDevice =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.setFeatures(dmsDevice.getFeatures()); if (dmsDevice != null) {
device.setProperties(dmsDevice.getProperties()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties());
}
devices.add(device); devices.add(device);
} }
return devices; return devices;

Loading…
Cancel
Save