Added some robustness
This commit is contained in:
parent
d3cd7287d5
commit
beac1c34c4
2 changed files with 14 additions and 10 deletions
|
|
@ -52,11 +52,13 @@ public class Event extends AbstractDevice<HalEventConfig,HalEventData>{
|
|||
if (deviceDataClass == null)
|
||||
throw new ClassNotFoundException("Unknown event data class for: " + getDeviceConfig().getClass());
|
||||
|
||||
PreparedStatement stmt = db.getPreparedStatement(
|
||||
"SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1");
|
||||
stmt.setLong(1, getId());
|
||||
return (HalEventData)
|
||||
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
|
||||
if (getId() != null) {
|
||||
PreparedStatement stmt = db.getPreparedStatement(
|
||||
"SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1");
|
||||
stmt.setLong(1, getId());
|
||||
return (HalEventData)
|
||||
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
|
||||
}
|
||||
} catch (Exception e){
|
||||
logger.log(Level.WARNING, null, e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,11 +121,13 @@ public class Sensor extends AbstractDevice<HalSensorConfig,HalSensorData>{
|
|||
if (deviceDataClass == null)
|
||||
throw new ClassNotFoundException("Unknown sensor data class for: " + getDeviceConfig().getClass());
|
||||
|
||||
PreparedStatement stmt = db.getPreparedStatement(
|
||||
"SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1");
|
||||
stmt.setLong(1, getId());
|
||||
return (HalSensorData)
|
||||
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
|
||||
if (getId() != null) {
|
||||
PreparedStatement stmt = db.getPreparedStatement(
|
||||
"SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1");
|
||||
stmt.setLong(1, getId());
|
||||
return (HalSensorData)
|
||||
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
|
||||
}
|
||||
} catch (Exception e){
|
||||
logger.log(Level.WARNING, null, e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue