(Context context)
| 526 | } |
| 527 | |
| 528 | private static RoomDatabase.Builder<DB> getBuilder(Context context) { |
| 529 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 530 | boolean wal = prefs.getBoolean("wal", true); |
| 531 | Log.i("DB wal=" + wal); |
| 532 | |
| 533 | RoomDatabase.Builder<DB> builder = Room |
| 534 | .databaseBuilder(context, DB.class, DB_NAME) |
| 535 | //.openHelperFactory(new RequerySQLiteOpenHelperFactory()) |
| 536 | //.setQueryExecutor() |
| 537 | .setTransactionExecutor(executor) |
| 538 | .setJournalMode(wal ? JournalMode.WRITE_AHEAD_LOGGING : JournalMode.TRUNCATE) // using the latest sqlite |
| 539 | .addCallback(new Callback() { |
| 540 | @Override |
| 541 | public void onCreate(@NonNull SupportSQLiteDatabase db) { |
| 542 | defaultSearches(db, context); |
| 543 | } |
| 544 | |
| 545 | @Override |
| 546 | public void onOpen(@NonNull SupportSQLiteDatabase db) { |
| 547 | try { |
| 548 | Map<String, String> crumb = new HashMap<>(); |
| 549 | crumb.put("version", Integer.toString(db.getVersion())); |
| 550 | crumb.put("WAL", Boolean.toString(db.isWriteAheadLoggingEnabled())); |
| 551 | Log.breadcrumb("Database", crumb); |
| 552 | |
| 553 | // https://www.sqlite.org/pragma.html#pragma_auto_vacuum |
| 554 | // https://android.googlesource.com/platform/external/sqlite.git/+/6ab557bdc070f11db30ede0696888efd19800475%5E!/ |
| 555 | boolean sqlite_auto_vacuum = prefs.getBoolean("sqlite_auto_vacuum", false); |
| 556 | String mode = (sqlite_auto_vacuum ? "FULL" : "INCREMENTAL"); |
| 557 | Log.i("Set PRAGMA auto_vacuum=" + mode); |
| 558 | try (Cursor cursor = db.query("PRAGMA auto_vacuum=" + mode + ";")) { |
| 559 | cursor.moveToNext(); // required |
| 560 | } |
| 561 | |
| 562 | // https://sqlite.org/pragma.html#pragma_synchronous |
| 563 | boolean sqlite_sync_extra = prefs.getBoolean("sqlite_sync_extra", true); |
| 564 | String sync = (sqlite_sync_extra ? "EXTRA" : "NORMAL"); |
| 565 | Log.i("Set PRAGMA synchronous=" + sync); |
| 566 | try (Cursor cursor = db.query("PRAGMA synchronous=" + sync + ";")) { |
| 567 | cursor.moveToNext(); // required |
| 568 | } |
| 569 | |
| 570 | // https://www.sqlite.org/pragma.html#pragma_journal_size_limit |
| 571 | Log.i("Set PRAGMA journal_size_limit=" + DB_JOURNAL_SIZE_LIMIT); |
| 572 | try (Cursor cursor = db.query("PRAGMA journal_size_limit=" + DB_JOURNAL_SIZE_LIMIT + ";")) { |
| 573 | cursor.moveToNext(); // required |
| 574 | } |
| 575 | |
| 576 | // https://www.sqlite.org/pragma.html#pragma_cache_size |
| 577 | Integer cache_size = getCacheSizeKb(context); |
| 578 | if (cache_size != null) { |
| 579 | cache_size = -cache_size; // kibibytes |
| 580 | Log.i("Set PRAGMA cache_size=" + cache_size); |
| 581 | // TODO CASA PRAGMA does not support placeholders |
| 582 | try (Cursor cursor = db.query("PRAGMA cache_size=" + cache_size + ";")) { |
| 583 | cursor.moveToNext(); // required |
| 584 | } |
| 585 | } |
no test coverage detected