Added some robustness

This commit is contained in:
Ziver Koc 2016-08-29 18:42:34 +02:00
parent d3cd7287d5
commit beac1c34c4
2 changed files with 14 additions and 10 deletions

View file

@ -52,11 +52,13 @@ public class Event extends AbstractDevice<HalEventConfig,HalEventData>{
if (deviceDataClass == null) if (deviceDataClass == null)
throw new ClassNotFoundException("Unknown event data class for: " + getDeviceConfig().getClass()); throw new ClassNotFoundException("Unknown event data class for: " + getDeviceConfig().getClass());
if (getId() != null) {
PreparedStatement stmt = db.getPreparedStatement( PreparedStatement stmt = db.getPreparedStatement(
"SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1"); "SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1");
stmt.setLong(1, getId()); stmt.setLong(1, getId());
return (HalEventData) return (HalEventData)
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass)); DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
}
} catch (Exception e){ } catch (Exception e){
logger.log(Level.WARNING, null, e); logger.log(Level.WARNING, null, e);
} }

View file

@ -121,11 +121,13 @@ public class Sensor extends AbstractDevice<HalSensorConfig,HalSensorData>{
if (deviceDataClass == null) if (deviceDataClass == null)
throw new ClassNotFoundException("Unknown sensor data class for: " + getDeviceConfig().getClass()); throw new ClassNotFoundException("Unknown sensor data class for: " + getDeviceConfig().getClass());
if (getId() != null) {
PreparedStatement stmt = db.getPreparedStatement( PreparedStatement stmt = db.getPreparedStatement(
"SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1"); "SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1");
stmt.setLong(1, getId()); stmt.setLong(1, getId());
return (HalSensorData) return (HalSensorData)
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass)); DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
}
} catch (Exception e){ } catch (Exception e){
logger.log(Level.WARNING, null, e); logger.log(Level.WARNING, null, e);
} }