]> git.ktnx.net Git - mobile-ledger.git/commitdiff
(commented) facility for debugging Room's SQL queries
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 22 Apr 2021 20:37:15 +0000 (23:37 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 22 Apr 2021 20:37:51 +0000 (23:37 +0300)
available in room 2.3.0

app/build.gradle
app/src/main/java/net/ktnx/mobileledger/db/DB.java

index 79f562173e13d4a622a74b4be38ba0727bb6fd89..fe0f8faf9cd956772c412b278b0d0aeddadd14f3 100644 (file)
@@ -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'
index cff1d9c14f62452ad80c0af679e81099477a1263..7e7ca4278d7c2460b0700d69643716d9ca19199a 100644 (file)
@@ -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<DB> 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) {