use of com.ichi2.libanki.backend.DroidBackend in project Anki-Android by ankidroid.
the class Storage method Collection.
public static Collection Collection(Context context, @NonNull String path, boolean server, boolean log, @NonNull Time time) {
assert (path.endsWith(".anki2") || path.endsWith(".anki21"));
File dbFile = new File(path);
boolean create = !dbFile.exists();
DroidBackend backend = DroidBackendFactory.getInstance(useBackend());
DB db = backend.openCollectionDatabase(sUseInMemory ? ":memory:" : path);
try {
// initialize
int ver;
if (create) {
ver = _createDB(db, time, backend);
} else {
ver = _upgradeSchema(db, time);
}
db.execute("PRAGMA temp_store = memory");
// add db to col and do any remaining upgrades
Collection col = backend.createCollection(context, db, path, server, log, time);
if (ver < Consts.SCHEMA_VERSION) {
_upgrade(col, ver);
} else if (ver > Consts.SCHEMA_VERSION) {
throw new RuntimeException("This file requires a newer version of Anki.");
} else if (create) {
addNoteTypes(col, backend);
col.onCreate();
col.save();
}
return col;
} catch (Exception e) {
Timber.e(e, "Error opening collection; closing database");
db.close();
throw e;
}
}
Aggregations