1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-18 06:37:47 +01:00

Good practice: use the DAO to insert/update instead of the session

(saves a few cycles to look up the correct DAO from the session)
This commit is contained in:
cpfeiffer 2016-08-27 23:12:48 +02:00
parent 840a125c81
commit 1a22259b4e
2 changed files with 8 additions and 8 deletions

View File

@ -258,7 +258,7 @@ public class DBHelper {
Calendar invalid = (Calendar) now.clone();
invalid.add(Calendar.MINUTE, -1);
userAttributes.setValidToUTC(invalid.getTime());
session.update(userAttributes);
session.getUserAttributesDao().update(userAttributes);
}
}
@ -380,7 +380,7 @@ public class DBHelper {
Calendar invalid = (Calendar) now.clone();
invalid.add(Calendar.MINUTE, -1);
deviceAttributes.setValidToUTC(invalid.getTime());
session.update(deviceAttributes);
session.getDeviceAttributesDao().update(deviceAttributes);
}
}
@ -416,7 +416,7 @@ public class DBHelper {
desc.setUser(user);
desc.setTimestampFrom(tsFrom);
desc.setTimestampTo(tsTo);
session.insertOrReplace(desc);
session.getActivityDescriptionDao().insertOrReplace(desc);
return desc;
}
@ -433,12 +433,12 @@ public class DBHelper {
return createTag(user, name, null, session);
}
static Tag createTag(@NonNull User user, @NonNull String name, @NonNull String description, @NonNull DaoSession session) {
static Tag createTag(@NonNull User user, @NonNull String name, @Nullable String description, @NonNull DaoSession session) {
Tag tag = new Tag();
tag.setUserId(user.getId());
tag.setName(name);
tag.setDescription(description);
session.insertOrReplace(tag);
session.getTagDao().insertOrReplace(tag);
return tag;
}

View File

@ -80,11 +80,11 @@ public class EntitiesTest {
attributes.setSleepGoalHPD(8);
attributes.setStepsGoalSPD(10000);
daoSession.insert(user);
daoSession.getUserDao().insert(user);
assertNotNull(user.getId());
attributes.setUserId(user.getId());
daoSession.insert(attributes);
daoSession.getUserAttributesDao().insert(attributes);
user.getUserAttributesList().add(attributes);
assertNotNull(userDao.load(user.getId()));
@ -95,7 +95,7 @@ public class EntitiesTest {
assertEquals(1, userAttributesDao.count());
assertEquals(1, daoSession.loadAll(UserAttributes.class).size());
daoSession.update(user);
daoSession.getUserDao().update(user);
daoSession.delete(user);
daoSession.delete(attributes);
daoSession.delete(attributes);