Added deletion of owned sensors when deleting a user and updated some traces. issue 17
Former-commit-id: 460f4058c97f2e48a16b7cb25fe8164d4a089061
This commit is contained in:
parent
afca115553
commit
bbb9996d56
3 changed files with 37 additions and 15 deletions
|
|
@ -95,10 +95,9 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
||||||
|
|
||||||
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
||||||
if(dataList.aggregationVersion != sensor.getAggregationVersion()){
|
if(dataList.aggregationVersion != sensor.getAggregationVersion()){
|
||||||
logger.fine("The peer has modified its aggregated data in such a way that we need to reset the sync and start over on this side. oldAggregationVersion:"+sensor.getAggregationVersion()+" , newAggregationVersion:"+dataList.aggregationVersion);
|
logger.fine("The peer has modified its aggregated data, clearing aggregate data. oldAggregationVersion:"+sensor.getAggregationVersion()+" , newAggregationVersion:"+dataList.aggregationVersion);
|
||||||
|
|
||||||
//clear old aggregated data for sensor
|
//clear old aggregated data for sensor
|
||||||
logger.finer("Deleting all aggregated data for sensor");
|
|
||||||
sensor.clearAggregatedData(db);
|
sensor.clearAggregatedData(db);
|
||||||
|
|
||||||
//save new aggregationVersion
|
//save new aggregationVersion
|
||||||
|
|
@ -118,7 +117,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
||||||
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " with offset "+ req.offsetSequenceId +" from " + user.getUsername());
|
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " with offset "+ req.offsetSequenceId +" from " + user.getUsername());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
logger.fine("Skipped sensor " + sensor.getId());
|
logger.fine("Sensor not marked for syncing, skipping sensor id: " + sensor.getId());
|
||||||
}
|
}
|
||||||
out.writeObject(null); // Tell server we are disconnecting
|
out.writeObject(null); // Tell server we are disconnecting
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,28 @@ public class Sensor extends AbstractDevice<HalSensorData>{
|
||||||
return (id != null ? id : 0);
|
return (id != null ? id : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will delete this Sensor and its aggregate data
|
||||||
|
* (raw data will never be deleted as a safety precaution!)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(DBConnection db) throws SQLException {
|
||||||
|
clearAggregatedData(db);
|
||||||
|
super.delete(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will clear all aggregated data for this Sensor and increment the AggregationVersion
|
||||||
|
*/
|
||||||
|
public void clearAggregatedData(DBConnection db) throws SQLException{
|
||||||
|
logger.fine("Clearing all aggregate data for sensor id: "+this.getId());
|
||||||
|
PreparedStatement stmt = db.getPreparedStatement( "DELETE FROM sensor_data_aggr WHERE sensor_id == ?" );
|
||||||
|
stmt.setLong(1, getId());
|
||||||
|
DBConnection.exec(stmt);
|
||||||
|
aggr_version++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getExternalId() {
|
public long getExternalId() {
|
||||||
return external_id;
|
return external_id;
|
||||||
|
|
@ -85,16 +106,6 @@ public class Sensor extends AbstractDevice<HalSensorData>{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Will clear all aggregated data for this Sensor and increment the AggregationVersion
|
|
||||||
*/
|
|
||||||
public void clearAggregatedData(DBConnection db) throws SQLException{
|
|
||||||
PreparedStatement stmt = db.getPreparedStatement( "DELETE FROM sensor_data_aggr WHERE sensor_id == ?" );
|
|
||||||
stmt.setLong(1, getId());
|
|
||||||
DBConnection.exec(stmt);
|
|
||||||
aggr_version++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Class<? extends HalSensorController> getController(){
|
public Class<? extends HalSensorController> getController(){
|
||||||
return getDeviceData().getSensorController();
|
return getDeviceData().getSensorController();
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,19 @@ public class User extends DBBean{
|
||||||
public static User getUser(DBConnection db, int id) throws SQLException {
|
public static User getUser(DBConnection db, int id) throws SQLException {
|
||||||
return DBBean.load(db, User.class, id);
|
return DBBean.load(db, User.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will delete this user and all its Sensors
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void delete(DBConnection db) throws SQLException {
|
||||||
|
List<Sensor> sensorList = Sensor.getSensors(db, this);
|
||||||
|
for(Sensor sensor : sensorList){
|
||||||
|
sensor.delete(db);
|
||||||
|
}
|
||||||
|
super.delete(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue