From: Damyan Ivanov Date: Thu, 22 Apr 2021 20:37:15 +0000 (+0300) Subject: (commented) facility for debugging Room's SQL queries X-Git-Tag: v0.18.0~53 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=f824d0b5541c9b7af2524d39813838ba131468f9;p=mobile-ledger.git (commented) facility for debugging Room's SQL queries available in room 2.3.0 --- diff --git a/app/build.gradle b/app/build.gradle index 79f56217..fe0f8faf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,7 +67,7 @@ android { dependencies { implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' - def room_version = '2.2.6' + def room_version = '2.3.0' implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" def nav_version = '2.3.5' diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DB.java b/app/src/main/java/net/ktnx/mobileledger/db/DB.java index cff1d9c1..7e7ca427 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/DB.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/DB.java @@ -69,30 +69,31 @@ abstract public class DB extends RoomDatabase { if (instance != null) return instance; - return instance = Room.databaseBuilder(App.instance, DB.class, DB_NAME) - .addMigrations(new Migration[]{singleVersionMigration(17), - singleVersionMigration(18), - singleVersionMigration(19), - singleVersionMigration(20), - multiVersionMigration(20, 22), - multiVersionMigration(22, 30), - multiVersionMigration(30, 32), - multiVersionMigration(32, 34), - multiVersionMigration(34, 40), - singleVersionMigration(41), - multiVersionMigration(41, 58), - singleVersionMigration(59) - }) - .addCallback(new Callback() { - @Override - public void onOpen(@NonNull SupportSQLiteDatabase db) { - super.onOpen(db); - db.execSQL("PRAGMA foreign_keys = ON"); - db.execSQL("pragma case_sensitive_like=ON;"); - - } - }) - .build(); + RoomDatabase.Builder builder = + Room.databaseBuilder(App.instance, DB.class, DB_NAME); + builder.addMigrations( + new Migration[]{singleVersionMigration(17), singleVersionMigration(18), + singleVersionMigration(19), singleVersionMigration(20), + multiVersionMigration(20, 22), multiVersionMigration(22, 30), + multiVersionMigration(30, 32), multiVersionMigration(32, 34), + multiVersionMigration(34, 40), singleVersionMigration(41), + multiVersionMigration(41, 58), singleVersionMigration(59) + }) + .addCallback(new Callback() { + @Override + public void onOpen(@NonNull SupportSQLiteDatabase db) { + super.onOpen(db); + db.execSQL("PRAGMA foreign_keys = ON"); + db.execSQL("pragma case_sensitive_like" + "=ON;"); + + } + }); + +// if (BuildConfig.DEBUG) +// builder.setQueryCallback(((sqlQuery, bindArgs) -> Logger.debug("room", sqlQuery)), +// Executors.newSingleThreadExecutor()); + + return instance = builder.build(); } } private static Migration singleVersionMigration(int toVersion) {