PersistenceService class
Stores running studies and the user task queue in a local SQLite database, so they survive an app restart.
A singleton, accessed as PersistenceService(). Initialized by
SmartPhoneClientManager.configure, which then restores studies and tasks.
It stores:
- Running studies on the phone as managed by the SmartphoneClientRepository
- User tasks on the task queue as managed by the AppTaskController
After init, changes are saved automatically: it listens to SmartphoneClientRepository.studyStatusEvents and AppTaskController.userTaskEvents. Database errors are logged, not thrown.
This is separate from the measurement database used by SQLiteDataManager.
Studies are stored in the studies table and user tasks are stored
in the task_queue table.
The path and filename format for the database is
~/carp.db
where ~ is the folder where SQLite places its database files.
On iOS, this is the NSDocumentsDirectory and the files can be accessed via
the MacOS Finder.
On Android, Flutter files are stored in the databases directory, which is
located in the data/data/<package_name>/databases/ folder.
Files can be accessed via AndroidStudio.
Constructors
- PersistenceService()
-
Get the singleton persistence layer.
factory
Properties
- databaseName → String
-
Full path and name of the database.
no setter
- databasePath → String
-
The folder holding the database. Set by init.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Closes the database. After this, no study or task can be read or saved.
-
getAllStudies(
) → Future< List< SmartphoneStudy> > - Get the list of all studies previously stored on this phone.
-
getStudy(
String studyDeploymentId, String deviceRoleName) → Future< SmartphoneStudy?> -
Return the SmartphoneStudy with
studyDeploymentIdanddeviceRoleName, or null when no such study is found. -
getUserTasks(
[SmartphoneStudy? study]) → Future< List< UserTaskSnapshot> > -
Get the list of UserTaskSnapshot for
study. Ifstudyis null, all user tasks are returned. -
init(
) → Future< void> - Opens (and if needed creates or migrates) the database, and starts saving study and task changes. Must be called before any other method. Does nothing if the database is already open.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeStudy(
Study< PrimaryDeviceDeployment> study) → Future<void> -
Removes
studyfrom the database. Its user tasks are not removed; use removeUserTasks for that. -
removeUserTasks(
[Study< PrimaryDeviceDeployment> ? study]) → Future<void> -
Remove the list of user tasks for
study. Ifstudyis null, all user tasks are removed. -
saveStudy(
SmartphoneStudy study) → Future< bool> -
Saves
study, replacing any existing row for it. Returnstrueif successful. -
saveUserTask(
UserTask task) → Future< void> -
Saves
taskto the task queue table, or deletes it if its state is UserTaskState.dequeued. -
toString(
) → String -
A string representation of this object.
inherited
-
updateStudy(
SmartphoneStudy study) → Future< bool> -
Updates the stored
study, matched on study deployment ID and device role name. Returnstrueif successful.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- CREATED_ON_COLUMN → const String
- DATABASE_NAME → const String
- DATABASE_VERSION → const int
- Schema version. Version 1 databases (including CAMS 1.x) are migrated on init.
- DEPLOYED_ON_COLUMN → const String
- DEPLOYMENT_COLUMN → const String
- DEPLOYMENT_STATUS_COLUMN → const String
- DEVICE_ROLE_NAME_COLUMN → const String
- ID_COLUMN → const String
- PARTICIPANT_ID_COLUMN → const String
- PARTICIPANT_ROLE_NAME_COLUMN → const String
- SAMPLING_STATUS_COLUMN → const String
- STUDY_DEPLOYMENT_ID_COLUMN → const String
- STUDY_ID_COLUMN → const String
- STUDY_TABLE_NAME → const String
- TASK_COLUMN → const String
- TASK_ID_COLUMN → const String
- TASK_QUEUE_TABLE_NAME → const String
- UPDATED_ON_COLUMN → const String