Search in sources :

Example 1 with DroidBackend

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;
    }
}
Also used : DroidBackend(com.ichi2.libanki.backend.DroidBackend) File(java.io.File) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FileNotFoundException(java.io.FileNotFoundException) JSONException(com.ichi2.utils.JSONException) UnknownDatabaseVersionException(com.ichi2.libanki.exception.UnknownDatabaseVersionException)

Aggregations

ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)1 DroidBackend (com.ichi2.libanki.backend.DroidBackend)1 UnknownDatabaseVersionException (com.ichi2.libanki.exception.UnknownDatabaseVersionException)1 JSONException (com.ichi2.utils.JSONException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1