-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix database id mapping to remove guesswork hacks
The SqliteDatabaseDriver had to resort to counter intuitive hacks to manually locate a database by its file name and didn't properly handle deduplicating multiple databases with the same name. As we expanded flexibility we failed to address the possibility (nay, likelihood) that this will occur and it would create very confusing results for users. This diff doesn't address the confusion in the UI (two database entries of the same name can still occur) but it internally makes it possible to treat them as separate databases and track their filenames separately. It also makes it relatively straightforward to fix the uniqueness of the user visible naming by introducing a "context" parameter to DatabaseDescriptor which would be used in the case of name ambiguity. This diff addresses concerns raised in #366 and #367.
- Loading branch information
Showing
8 changed files
with
355 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
62 changes: 62 additions & 0 deletions
62
stetho/src/main/java/com/facebook/stetho/inspector/database/DatabaseDriver2Adapter.java
This file contains 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,62 @@ | ||
package com.facebook.stetho.inspector.database; | ||
|
||
import android.database.sqlite.SQLiteException; | ||
|
||
import com.facebook.stetho.inspector.protocol.module.Database; | ||
import com.facebook.stetho.inspector.protocol.module.DatabaseDescriptor; | ||
import com.facebook.stetho.inspector.protocol.module.DatabaseDriver; | ||
import com.facebook.stetho.inspector.protocol.module.DatabaseDriver2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @deprecated Use {@link DatabaseDriver2} directly. This is provided only for legacy | ||
* drivers to be adapted internally within Stetho. | ||
*/ | ||
@Deprecated | ||
public class DatabaseDriver2Adapter | ||
extends DatabaseDriver2<DatabaseDriver2Adapter.StringDatabaseDescriptor> { | ||
private final DatabaseDriver mLegacy; | ||
|
||
public DatabaseDriver2Adapter(DatabaseDriver legacy) { | ||
super(legacy.getContext()); | ||
mLegacy = legacy; | ||
} | ||
|
||
@Override | ||
public List<StringDatabaseDescriptor> getDatabaseNames() { | ||
List<?> names = mLegacy.getDatabaseNames(); | ||
List<StringDatabaseDescriptor> descriptors = new ArrayList<>(names.size()); | ||
for (Object name : names) { | ||
descriptors.add(new StringDatabaseDescriptor(name.toString())); | ||
} | ||
return descriptors; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public List<String> getTableNames(StringDatabaseDescriptor database) { | ||
return mLegacy.getTableNames(database.name); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public Database.ExecuteSQLResponse executeSQL( | ||
StringDatabaseDescriptor database, | ||
String query, | ||
ExecuteResultHandler handler) throws SQLiteException { | ||
return mLegacy.executeSQL(database.name, query, handler); | ||
} | ||
|
||
static class StringDatabaseDescriptor implements DatabaseDescriptor { | ||
public final String name; | ||
|
||
public StringDatabaseDescriptor(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
} | ||
} |
Oops, something went wrong.