-
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.
Merge pull request #392 from jasta/databaseid-mapping
Fix database id mapping to remove guesswork hacks
- Loading branch information
Showing
8 changed files
with
358 additions
and
131 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
61 changes: 61 additions & 0 deletions
61
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,61 @@ | ||
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.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 Database.DatabaseDriver mLegacy; | ||
|
||
public DatabaseDriver2Adapter(Database.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.