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());
PreparedStatement stmt = db.getPreparedStatement( if (getId() != null) {
"SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1"); PreparedStatement stmt = db.getPreparedStatement(
stmt.setLong(1, getId()); "SELECT data FROM event_data_raw WHERE event_id == ? ORDER BY timestamp DESC LIMIT 1");
return (HalEventData) stmt.setLong(1, getId());
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass)); return (HalEventData)
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());
PreparedStatement stmt = db.getPreparedStatement( if (getId() != null) {
"SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1"); PreparedStatement stmt = db.getPreparedStatement(
stmt.setLong(1, getId()); "SELECT data FROM sensor_data_raw WHERE sensor_id == ? ORDER BY timestamp DESC LIMIT 1");
return (HalSensorData) stmt.setLong(1, getId());
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass)); return (HalSensorData)
DBConnection.exec(stmt, new DeviceDataSqlResult(deviceDataClass));
}
} catch (Exception e){ } catch (Exception e){
logger.log(Level.WARNING, null, e); logger.log(Level.WARNING, null, e);
} }