[core] Update database (#990)
This commit is contained in:
parent
42ddca8b05
commit
04352a7da6
|
|
@ -140,14 +140,15 @@ public class ConfigManager {
|
||||||
"user_id integer NOT NULL," +
|
"user_id integer NOT NULL," +
|
||||||
"PRIMARY KEY (mid, app_pkg_name, user_id)" +
|
"PRIMARY KEY (mid, app_pkg_name, user_id)" +
|
||||||
");");
|
");");
|
||||||
private final SQLiteStatement createConfigTable = db.compileStatement("CREATE TABLE IF NOT EXISTS config (" +
|
private final SQLiteStatement createConfigTable = db.compileStatement("CREATE TABLE IF NOT EXISTS configs (" +
|
||||||
"module_pkg_name text NOT NULL," +
|
"module_pkg_name text NOT NULL," +
|
||||||
"user_id integer NOT NULL," +
|
"user_id integer NOT NULL," +
|
||||||
"`group` text NOT NULL," +
|
"`group` text NOT NULL," +
|
||||||
"`key` text NOT NULL," +
|
"`key` text NOT NULL," +
|
||||||
"data blob NOT NULL," +
|
"data blob NOT NULL," +
|
||||||
"PRIMARY KEY (module_pkg_name, user_id)" +
|
"PRIMARY KEY (module_pkg_name, user_id, `group`, `key`)" +
|
||||||
");");
|
");");
|
||||||
|
private final SQLiteStatement createConfigIndex = db.compileStatement("CREATE INDEX IF NOT EXISTS configs_idx ON configs (module_pkg_name, user_id);");
|
||||||
|
|
||||||
private final Map<ProcessScope, List<Module>> cachedScope = new ConcurrentHashMap<>();
|
private final Map<ProcessScope, List<Module>> cachedScope = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
@ -287,6 +288,7 @@ public class ConfigManager {
|
||||||
createModulesTable.execute();
|
createModulesTable.execute();
|
||||||
createScopeTable.execute();
|
createScopeTable.execute();
|
||||||
createConfigTable.execute();
|
createConfigTable.execute();
|
||||||
|
createConfigIndex.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ProcessScope> getAssociatedProcesses(Application app) throws RemoteException {
|
private List<ProcessScope> getAssociatedProcesses(Application app) throws RemoteException {
|
||||||
|
|
@ -302,7 +304,7 @@ public class ConfigManager {
|
||||||
Map<String, ConcurrentHashMap<String, Object>> fetchModuleConfig(String name, int user_id) {
|
Map<String, ConcurrentHashMap<String, Object>> fetchModuleConfig(String name, int user_id) {
|
||||||
var config = new ConcurrentHashMap<String, ConcurrentHashMap<String, Object>>();
|
var config = new ConcurrentHashMap<String, ConcurrentHashMap<String, Object>>();
|
||||||
|
|
||||||
try (Cursor cursor = db.query("config", new String[]{"`group`", "`key`", "data"},
|
try (Cursor cursor = db.query("configs", new String[]{"`group`", "`key`", "data"},
|
||||||
"module_pkg_name = ? and user_id = ?", new String[]{name, String.valueOf(user_id)}, null, null, null)) {
|
"module_pkg_name = ? and user_id = ?", new String[]{name, String.valueOf(user_id)}, null, null, null)) {
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
Log.e(TAG, "db cache failed");
|
Log.e(TAG, "db cache failed");
|
||||||
|
|
@ -334,10 +336,10 @@ public class ConfigManager {
|
||||||
values.put("data", SerializationUtils.serialize((Serializable) value));
|
values.put("data", SerializationUtils.serialize((Serializable) value));
|
||||||
values.put("module_pkg_name", moduleName);
|
values.put("module_pkg_name", moduleName);
|
||||||
values.put("user_id", String.valueOf(userId));
|
values.put("user_id", String.valueOf(userId));
|
||||||
db.insertWithOnConflict("config", null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
db.insertWithOnConflict("configs", null, values, SQLiteDatabase.CONFLICT_REPLACE);
|
||||||
} else {
|
} else {
|
||||||
prefs.remove(key);
|
prefs.remove(key);
|
||||||
db.delete("config", "module_pkg_name=? and user_id=? and `group`=? and `key`=?", new String[]{moduleName, String.valueOf(userId), group, key});
|
db.delete("configs", "module_pkg_name=? and user_id=? and `group`=? and `key`=?", new String[]{moduleName, String.valueOf(userId), group, key});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue