BgReading: add sourcePlugin and filtered fields.

This commit is contained in:
Johannes Mockenhaupt 2018-06-22 18:10:10 +02:00
parent 4efb115209
commit 98c933af57
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 23 additions and 10 deletions

View file

@ -38,6 +38,10 @@ public class BgReading implements DataPointWithLabelInterface {
public String direction; public String direction;
@DatabaseField @DatabaseField
public double raw; public double raw;
@DatabaseField
public boolean filtered;
@DatabaseField
public String sourcePlugin;
@DatabaseField @DatabaseField
public int source = Source.NONE; public int source = Source.NONE;
@ -120,19 +124,11 @@ public class BgReading implements DataPointWithLabelInterface {
", value=" + value + ", value=" + value +
", direction=" + direction + ", direction=" + direction +
", raw=" + raw + ", raw=" + raw +
", filtered=" + filtered +
", sourcePlugin=" + sourcePlugin +
'}'; '}';
} }
public boolean isDataChanging(BgReading other) {
if (date != other.date) {
log.error("Comparing different");
return false;
}
if (value != other.value)
return true;
return false;
}
public boolean isEqual(BgReading other) { public boolean isEqual(BgReading other) {
if (date != other.date) { if (date != other.date) {
log.error("Comparing different"); log.error("Comparing different");
@ -158,6 +154,8 @@ public class BgReading implements DataPointWithLabelInterface {
raw = other.raw; raw = other.raw;
direction = other.direction; direction = other.direction;
_id = other._id; _id = other._id;
sourcePlugin = other.sourcePlugin;
filtered = other.filtered;
} }
// ------------------ DataPointWithLabelInterface ------------------ // ------------------ DataPointWithLabelInterface ------------------

View file

@ -117,12 +117,27 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class); TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class); TableUtils.createTableIfNotExists(connectionSource, ProfileSwitch.class);
TableUtils.createTableIfNotExists(connectionSource, TDD.class); TableUtils.createTableIfNotExists(connectionSource, TDD.class);
// soft migration without changing DB version
createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS,
"filtered", "integer");
createRowIfNotExists(getDaoBgReadings(), DatabaseHelper.DATABASE_BGREADINGS,
"sourcePlugin", "integer");
} catch (SQLException e) { } catch (SQLException e) {
log.error("Can't create database", e); log.error("Can't create database", e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private void createRowIfNotExists(Dao dao, String table, String name, String type) {
try {
dao.executeRaw("ALTER TABLE `" + table + "` ADD CoLUMN `" + name + " " + type);
} catch (SQLException e) {
// row already exists
}
}
@Override @Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try { try {