-
Notifications
You must be signed in to change notification settings - Fork 24
ADFA-3879 resilient LastChange table #1302
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
Open
hal-eisen-adfa
wants to merge
5
commits into
stage
Choose a base branch
from
ADFA-3879-resilient-wholedb-missing-from-LastChange
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
634b800
Handle missing documentation.db LastChange wholedb record by fallback…
hal-eisen-adfa ad4317c
Delete app/src/debug/java/com/itsaky/androidide/idetooltips/TooltipSc…
hal-eisen-adfa 3d10fc5
Delete app/src/androidTest/kotlin/com/itsaky/androidide/idetooltips/T…
hal-eisen-adfa 4c6fe7d
Delete app/src/debug/AndroidManifest.xml
hal-eisen-adfa 9632d47
Merge branch 'stage' into ADFA-3879-resilient-wholedb-missing-from-La…
hal-eisen-adfa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
common/src/androidTest/java/com/itsaky/androidide/utils/DatabaseVersionResolverTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package com.itsaky.androidide.utils | ||
|
|
||
| import android.database.sqlite.SQLiteDatabase | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class DatabaseVersionResolverTest { | ||
|
|
||
| private lateinit var db: SQLiteDatabase | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| db = SQLiteDatabase.openOrCreateDatabase(":memory:", null) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| db.close() | ||
| } | ||
|
|
||
| private fun createTable() { | ||
| db.execSQL( | ||
| "CREATE TABLE LastChange (" + | ||
| "documentationSet TEXT, " + | ||
| "changeTime TEXT, " + | ||
| "who TEXT)" | ||
| ) | ||
| } | ||
|
|
||
| private fun insertRow(documentationSet: String, changeTime: String, who: String?) { | ||
| db.execSQL( | ||
| "INSERT INTO LastChange (documentationSet, changeTime, who) VALUES (?, ?, ?)", | ||
| arrayOf<Any?>(documentationSet, changeTime, who), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun returnsWholedbRow_whenPresent() { | ||
| createTable() | ||
| insertRow("wholedb", "2026-05-09 02:00:20", "hal") | ||
| insertRow("tooltips-ide", "2026-05-09 02:00:20", "hal") | ||
|
|
||
| assertEquals( | ||
| "2026-05-09 02:00:20 hal", | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun fallsBackToLatestRow_whenWholedbMissing() { | ||
| createTable() | ||
| insertRow("tooltips-ide", "2026-05-09 02:00:20", "hal") | ||
| insertRow("content-y", "2026-05-01 17:42:29", "hal") | ||
| insertRow("tooltips-java", "2026-05-09 01:58:37", "hal") | ||
|
|
||
| assertEquals( | ||
| "2026-05-09 02:00:20 (tooltips-ide) hal", | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun returnsVersionUnknown_whenTableEmpty() { | ||
| createTable() | ||
|
|
||
| assertEquals( | ||
| DatabaseVersionResolver.VERSION_UNKNOWN, | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun returnsVersionUnknown_whenTableMissing() { | ||
| // Intentionally do not create the LastChange table. | ||
| assertEquals( | ||
| DatabaseVersionResolver.VERSION_UNKNOWN, | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun handlesNullWho_onWholedbRow() { | ||
| createTable() | ||
| insertRow("wholedb", "2026-05-09 02:00:20", null) | ||
|
|
||
| assertEquals( | ||
| "2026-05-09 02:00:20", | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun handlesNullWho_onFallbackRow() { | ||
| createTable() | ||
| insertRow("tooltips-ide", "2026-05-09 02:00:20", null) | ||
|
|
||
| assertEquals( | ||
| "2026-05-09 02:00:20 (tooltips-ide)", | ||
| DatabaseVersionResolver.resolveDatabaseVersion(db), | ||
| ) | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
common/src/main/java/com/itsaky/androidide/utils/DatabaseVersionResolver.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package com.itsaky.androidide.utils | ||
|
|
||
| import android.database.sqlite.SQLiteDatabase | ||
| import android.util.Log | ||
|
|
||
| object DatabaseVersionResolver { | ||
|
|
||
| const val VERSION_UNKNOWN = "Version Unknown" | ||
|
|
||
| private const val TAG = "DatabaseVersionResolver" | ||
|
|
||
| private const val QUERY_WHOLEDB = """ | ||
| SELECT changeTime, who | ||
| FROM LastChange | ||
| WHERE documentationSet = 'wholedb' | ||
| LIMIT 1 | ||
| """ | ||
|
|
||
| private const val QUERY_FALLBACK_LATEST = """ | ||
| SELECT changeTime, documentationSet, who | ||
| FROM LastChange | ||
| ORDER BY changeTime DESC | ||
| LIMIT 1 | ||
| """ | ||
|
|
||
| fun resolveDatabaseVersion(db: SQLiteDatabase): String { | ||
| return try { | ||
| db.rawQuery(QUERY_WHOLEDB, arrayOf()).use { c -> | ||
| if (c.moveToFirst()) { | ||
| return formatVersion( | ||
| changeTime = c.getString(0), | ||
| who = c.getString(1), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| db.rawQuery(QUERY_FALLBACK_LATEST, arrayOf()).use { c -> | ||
| if (c.moveToFirst()) { | ||
| val result = formatVersion( | ||
| changeTime = c.getString(0), | ||
| who = c.getString(2), | ||
| documentationSet = c.getString(1), | ||
| ) | ||
| Log.e( | ||
| TAG, | ||
| "Missing 'wholedb' record in LastChange table; falling back to $result", | ||
| ) | ||
| return result | ||
| } | ||
| } | ||
|
|
||
| Log.e(TAG, "No versioning information available") | ||
| VERSION_UNKNOWN | ||
| } catch (e: Exception) { | ||
| Log.e(TAG, "No versioning information available", e) | ||
| VERSION_UNKNOWN | ||
| } | ||
| } | ||
|
|
||
| private fun formatVersion( | ||
| changeTime: String?, | ||
| who: String?, | ||
| documentationSet: String? = null, | ||
| ): String { | ||
| val parts = mutableListOf<String>() | ||
| if (!changeTime.isNullOrBlank()) parts += changeTime | ||
| if (!documentationSet.isNullOrBlank()) parts += "($documentationSet)" | ||
| if (!who.isNullOrBlank()) parts += who | ||
| return parts.joinToString(separator = " ") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.