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

Replaced greenDAO with androidx.room #506

Draft
wants to merge 127 commits into
base: develop
Choose a base branch
from
Draft

Conversation

JaniruTEC
Copy link
Contributor

@JaniruTEC JaniruTEC commented Oct 18, 2023

Summary by CodeRabbit

  • New Features

    • Introduced Room library for enhanced database management.
    • Added new tests for database creation, access, and migrations.
    • Implemented automatic and manual database migrations for improved data integrity.
    • Added new data access objects (DAOs) for Cloud, Update Check, and Vault entities.
  • Enhancements

    • Improved database operation efficiency by utilizing Kotlin's type alias and constructor-based entity creation.
    • Enhanced database schema with the addition of entities for Cloud, Update Check, and Vault.
    • Streamlined database access in repository implementations with dependency injection.
  • Bug Fixes

    • Fixed issues related to database migrations and entity mapping for a more stable user experience.
  • Refactor

    • Transitioned from GreenDao to Room for database operations, resulting in cleaner and more maintainable code.
    • Refined database migration logic to use Room's built-in migration features.
  • Documentation

    • Updated internal comments to reflect changes in database handling and migration processes.
  • Chores

    • Updated build configurations to include necessary Room library dependencies.

Replaced greenDAO dependency with androidx.room
Introduced database version 13
Introduced database version 14
@JaniruTEC JaniruTEC requested a review from SailReal October 18, 2023 13:52
@JaniruTEC JaniruTEC marked this pull request as draft October 18, 2023 13:52
@CLAassistant

This comment was marked as resolved.

JaniruTEC added 30 commits June 19, 2024 21:30
Also added matching data sets
Added method "cartesianProductFour"

*This commit is related to issue #529 [1]*

[1] #529
Unified the implementation of "testInsert" with the implemention of all tests contained in "MappingSupportSQLiteStatementTest" by first augmenting and moving the implementation of "testSingleNewBoundStatement" to a new method "testSingleCompiledStatement" and then using that method in "testInsert":
> Previous control flows:
>> "testNewBoundStatementX" -> ("testConsecutiveNewBoundStatements" ->) "testConsecutiveNewBoundStatements" -> "testSingleNewBoundStatement" -> *Verifications*
>> "testInsert" -> *Verifications*
> New control flows:
>> "testNewBoundStatementX" -> ("testConsecutiveNewBoundStatements" ->) "testConsecutiveNewBoundStatements" -> "testSingleNewBoundStatement" -> "testSingleCompiledStatement" -> *Verifications*
>> "testInsert" -> "testSingleInsert" -> "testSingleCompiledStatement" -> *Verifications*

Removed extensions methods for "ContentValues" defined in "MappingSupportSQLiteDatabaseTest.kt" and replaced usages with calls to corresponding extension methods for "Iterable<Any?>?" defined in "MappingSupportSQLiteDatabaseTest.kt"

*This commit is related to issue #529 [1]*

[1] #529
*This commit is related to issue #529 [1]*

[1] #529
Removed TODOs
Added delegating method with closing logic and default arguments
Added room-grade-plugin to build
Moved appropriate configuration to room-grade-plugin
Swapped bindings storage from lambdas to actual values
Added additional copy-operation to ByteArray-bindings to prevent downstream changes
Added utility methods

*This commit is related to issue #529 [1]*

[1] #529
*This commit is related to issue #529 [1]*

[1] #529
Moved call to "asCacheControlled" for singleton instance of "DatabaseOpenHelperFactory" from "DatabaseModule.provideInternalCryptomatorDatabase" to new binding "DatabaseModule.provideOpenHelperFactory" to prevent unnecessary duplicate invocations

*This commit is related to issue #529 [1]*

[1] #529
Added logic to delete templates after use
Improved template verification
Changed binding type of templates from singleton to single-use
Changed type of exposed binding to "InputStream"
Updated "TemplateDatabaseContextTest", "CorruptedDatabaseTest", "CreateDatabaseTest" and "UpgradeDatabaseTest"
Refactored database configuration in "CreateDatabaseTest" and "UpgradeDatabaseTest" to follow standard laid out by production logic/other tests
Refactored "CreateDatabaseTest" and "UpgradeDatabaseTest" to close databases following the standard laid out by production logic/other tests
*This commit is related to issue #529 [1]*

[1] #529
Moved WAL initialization from the "onConfigure" methods (via "applyDefaultConfiguration") of the database configurations to the corresponding instances of "SupportSQLiteOpenHelper"
Updated extension method "applyDefaultConfiguration" for "SupportSQLiteDatabase" defined in "CryptomatorDatabase.kt" to no longer configure WAL but verify that it has been set properly in the corresponding "SupportSQLiteOpenHelper"

*This commit is related to issue #529 [1]*

[1] #529
Added comments and documentation
Simplified implementation for "RandomUUIDMapping.mapWhereClause"
Replaced import alias "org.mockito.Mockito.`when` as whenCalled" with built-in "org.mockito.kotlin.whenever" in "MappingSupportSQLiteDatabaseTest.kt"

*This commit is related to issue #529 [1]*

[1] #529
*This commit is related to issue #529 [1]*

[1] #529
*This commit is related to issue #529 [1]*

[1] #529
Added "@VisibleForTesting" to "MappingSupportSQLiteQuery" and changed its visibility to internal

*This commit is related to issue #529 [1]*

[1] #529
Added missing fields defined by upstream v13 to "CloudEntity", "VaultEntity" and "AutoMigration14To15"
Added room-generated database schema for v15 as "15.json"
Moved "Upgrade12To13" and made it runnable
Replaced calls in "Upgrade12To13" with matching "pre15"-calls
Added "Upgrade12To13" to migration path in "DatabaseModule"

--

About this commit, as well as 4aa1c90 and c9a0d3d:

A new database version (13) introduced in the upstream by ac5f3ff/#547 [1] (merged into develop by 7a37c03) needs to be merged into the "feature/dao-migration"-branch used for working on #506 [2].
4aa1c90 prepared the merge by bumping the versions defined by "feature/dao-migration" from 13 (l12-v1-r2-13) and 14 (l12-v2-r3-14) to 14 (l13-v1-r1-14) and 15 (l13-v2-r1-15).
l13-v1-r1-14 supersedes l12-v1-r2-13 and l13-v2-r1-15 supersedes l12-v2-r3-14 by applying the changes introduced by the upstream v13.
The relation between l13-v1-r1-14 and l13-v2-r1-15 is the same as between l12-v1-r2-13 and l12-v2-r3-14, i.e. the changes introduced by the upstream v13 are handled according to the semantics defined by that relation.
4aa1c90 deleted "13.json" (was l12-v1-r2-13) and replaced the content of "14.json" (was l12-v2-r3-14) with l13-v1-r1-14, which is the version that supersedes l12-v1-r2-13.
It therefore changes the migration path from [...] -> v12 -> v13 (l12-v1-r2-13) -> v14 (l12-v2-r3-14) to [...] -> v12 -> [Not yet merged upstream v13] -> v14 (l13-v1-r1-14) -> v15 (l13-v2-r1-15).

c9a0d3d merged the upstream v13 (c970438) into 4aa1c90 and made the migration path continuous again: [...] -> v12 -> upstream v13 -> v14 (l13-v1-r1-14) -> v15 (l13-v2-r1-15)

This commit finishes this merge for the production source.
It adds "15.json" with l13-v2-r1-15 as its content, which is the version that supersedes l12-v2-r3-14.
Therefore "13.json" (l12-v1-r2-13) and "14.json" (l12-v2-r3-14) are superseded by "14.json" (l13-v1-r1-14) and "15.json" (l13-v2-r1-15) respectively.
It also applies l13-v2-r1-15 to "CloudEntity" and "VaultEntity", as well as "AutoMigration14To15".

[1] #547
[2] #506

Version definitions:
l12-v1-r2-13: e1bd29a
l12-v2-r3-14: 23887b4
l13-v1-r1-14: 9536283
l13-v2-r1-15: 074c77d
Uncommented the tests
Removed outdated calls to "Upgrade0To1"
Replaced calls to removed method "applyTo" with calls to "migrate"
Replaced raw arrays and consecutive invocations of migrations with usages of "MigrationContainer"
Moved initialization/property for "MigrationContainer" from "testOpenVersion0Database" to "setup"/class body
Cleaned up "testOpenVersion0Database"
Replaced "openHelperFactory" property with method
Moved logic for configuring a test database, a "MigrationContainer" and creating a v0 database to "DatabaseTests.kt"

*This commit is related to issue #529 [1]*

[1] #529
Added "assertOrder" to simplify orders that contain multiple calls to the same assertion
Fixed "testOpenVersion0DatabaseVerifyStreamAccessed":
"CorruptedDatabaseTest.kt:103" calls "RoomDatabase.compileStatement", which contains two calls to "writableDatabase" that were not previously accounted for.

Fixed "testOpenDatabaseWithRecovery":
The assertion in "CorruptedDatabaseTest.kt:129" is called by "PatchedCallback.onCreate" in "DatabaseOpenHelperFactory.kt:61", which is called by "FrameworkSQLiteOpenHelper.OpenHelper.innerGetDatabase". "PatchedCallback.onCreate" then calls "DatabaseCallback.onCreate", which then throws the "UnsupportedOperationException" ("DatabaseModule.kt:137") expected by the assertion in "CorruptedDatabaseTest.kt:123". However, it was not previously taken into account that "FrameworkSQLiteOpenHelper.OpenHelper.innerGetDatabase" discards the first thrown exception and tries again, which results in a second call to "PatchedCallback.onCreate" and therefore a second call to the assertion in "CorruptedDatabaseTest.kt:129" before the assertion in "CorruptedDatabaseTest.kt:123" is reached.
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.

2 participants