Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Room persistence library to access the database #108

Merged
merged 17 commits into from
Mar 26, 2024

Conversation

0xC0FFEEC0DE
Copy link
Collaborator

Room persistence library makes database access and future database extensions easier.

Christian Adams added 17 commits February 28, 2024 22:44
- build.gradle: Added room dependencies, added javaCompileOptions to export DB schema (schemas/org.secuso.privacyfriendlytodolist.model.database.TodoListDatabase/3.json)
- Changes at model:
   - Hiding all classes behind interfaces
   - Kept model services as abstract as possible, tried to hide the SQL DB
   - Usage of room persistence library
- Changed from DBQueryHandler to ModelServices to make use of new model
General changes:
- Fixed spelling: Renamed subTask to subtask
- Used interface List instead of ArrayList where possible

Current state of migration: It compiles but did not run.
Open task: First tests and bug fixes.
Optional: Create unit tests in development branch for old DB access method. Pull them into this branch and let them run against room implementation.
…hrows exception if called from main thread and tells that such actions should be done async from main thread to not freeze the UI.

To solve that issue started to do DB access async:
- Made work of ReminderService via WorkerManager async (ReminderWorker).
- Create ViewModelServices to make DB access from UI classes async. Started at MainActivity.

Delete translated texts which were used for log statements only because log statements were deleted.
…rence to parent activity as FragmentActivity reference. It gets used as context, ViewModelStoreOwner and LifecycleOwner.
- minSdkVersion 17 -> 19 to be able to change lifecycle-viewmodel-ktx:2.4.1 -> 2.7.0
- Changed from kotlin-kapt to KSP
- Applied suggestion variant.outputs.all -> variant.outputs.configureEach
build.gradle:
- Applied suggestion to change repository jcenter() -> mavenCentral()
- Applied suggestion task clean(type: Delete) -> tasks.register("clean", Delete)
Major change:
- Based on https://developer.android.com/training/data-storage/room/async-queries decided to use Coroutines (suspend) to implement asynchronous DB access
- Created CustomViewModel for classes that do not implement ViewModelStoreOwner and therefore can't get LifecycleViewModel from ViewModelProvider
- With that no separate worker for ReminderService is needed anymore. Merged ReminderService and ReminderWorker again
- Created ResultConsumer interface as callback for coroutines
- Changed ALL calls of data model to do subsequent actions in such a callback
Auto-organized imports.
…igrationTestHelper class to test migration.
Added DB migration from v1 to v2 to v3.
Added DB migration tests.
… key to show that it does not belong to a list (DUMMY_LIST_ID = -3). But now with Room API this triggers an exception that foreign key constraint was not met.

To solve this the foreign key of todo-tasks was changed from int to nullable int. null value does not trigger this exception.
Bugs fixed:
- At inserting into DB the new row ID now gets stored manually in the object. This is not done by room.
- Task description was not stored at DB because shadow variable did exist. Now its removed.
…e as in the previous releases. Otherwise Room will not see old database and therefore will not start DB migration.
@0xC0FFEEC0DE 0xC0FFEEC0DE self-assigned this Mar 26, 2024
@0xC0FFEEC0DE 0xC0FFEEC0DE merged commit b388be4 into development Mar 26, 2024
12 checks passed
@0xC0FFEEC0DE 0xC0FFEEC0DE deleted the room-lib branch March 26, 2024 15:31
@0xC0FFEEC0DE 0xC0FFEEC0DE added this to the Upcoming Release ?.?.? milestone Apr 12, 2024
This was referenced Apr 12, 2024
@udenr udenr mentioned this pull request Nov 21, 2024
This was referenced Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant