From f824d0b5541c9b7af2524d39813838ba131468f9 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 22 Apr 2021 23:37:15 +0300 Subject: [PATCH] (commented) facility for debugging Room's SQL queries available in room 2.3.0 --- app/build.gradle | 2 +- .../java/net/ktnx/mobileledger/db/DB.java | 49 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) 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) { -- 2.39.5