1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package androidx.room 17 18 import android.annotation.SuppressLint 19 import android.content.Context 20 import android.content.Intent 21 import androidx.annotation.RestrictTo 22 import androidx.room.migration.AutoMigrationSpec 23 import androidx.room.util.isMigrationRequired as isMigrationRequiredExt 24 import androidx.sqlite.SQLiteDriver 25 import androidx.sqlite.db.SupportSQLiteOpenHelper 26 import java.io.File 27 import java.io.InputStream 28 import java.util.concurrent.Callable 29 import java.util.concurrent.Executor 30 import kotlin.coroutines.CoroutineContext 31 32 /** Configuration class for a [RoomDatabase]. */ 33 @Suppress("UNUSED_PARAMETER") 34 actual open class DatabaseConfiguration 35 @SuppressLint("LambdaLast") 36 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 37 constructor( 38 /* The context to use while connecting to the database. */ 39 @JvmField val context: Context, 40 41 /* The name of the database file or null if it is an in-memory database. */ 42 @JvmField actual val name: String?, 43 44 /* The factory to use to access the database. */ 45 @JvmField val sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory?, 46 47 /* Collection of available migrations. */ 48 @JvmField actual val migrationContainer: RoomDatabase.MigrationContainer, 49 50 /* Database callbacks. */ 51 @JvmField actual val callbacks: List<RoomDatabase.Callback>?, 52 53 /* Whether Room should throw an exception for queries run on the main thread. */ 54 @JvmField val allowMainThreadQueries: Boolean, 55 56 /* The journal mode for this database. */ 57 @JvmField actual val journalMode: RoomDatabase.JournalMode, 58 59 /* The Executor used to execute asynchronous queries. */ 60 @JvmField val queryExecutor: Executor, 61 62 /* The Executor used to execute asynchronous transactions. */ 63 @JvmField val transactionExecutor: Executor, 64 65 /** 66 * Intent that should be bound to acquire the invalidation service or `null` if not used. 67 * 68 * @see [multiInstanceInvalidation] 69 */ 70 @field:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 71 @JvmField 72 val multiInstanceInvalidationServiceIntent: Intent?, 73 74 /* Whether Room should throw an exception for missing migrations. */ 75 @JvmField actual val requireMigration: Boolean, 76 77 /* Whether Room will fallback to destructive migrations on downgrades only .*/ 78 @JvmField actual val allowDestructiveMigrationOnDowngrade: Boolean, 79 internal actual val migrationNotRequiredFrom: Set<Int>?, 80 81 /* Asset path of pre-package database or null if not used. */ 82 @JvmField val copyFromAssetPath: String?, 83 84 /* File of pre-package database or null if not used. */ 85 @JvmField val copyFromFile: File?, 86 87 /* Input stream of pre-package database or null if not used. */ 88 @JvmField val copyFromInputStream: Callable<InputStream>?, 89 90 /* Callback when Room uses a pre-packaged database. */ 91 @JvmField val prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback?, 92 93 /* List of provided type converters. */ 94 @JvmField actual val typeConverters: List<Any>, 95 96 /* List of provided auto migration specs. */ 97 @JvmField actual val autoMigrationSpecs: List<AutoMigrationSpec>, 98 99 /* Whether Room will delete all tables or only known tables during destructive migrations. */ 100 @JvmField actual val allowDestructiveMigrationForAllTables: Boolean, 101 102 /* The SQLite Driver for the database. */ 103 @JvmField actual val sqliteDriver: SQLiteDriver?, 104 105 /* The Coroutine context for the database. */ 106 @JvmField actual val queryCoroutineContext: CoroutineContext?, 107 ) { 108 /** 109 * If true, table invalidation in an instance of [RoomDatabase] is broadcast and synchronized 110 * with other instances of the same [RoomDatabase] file, including those in a separate process. 111 */ 112 @JvmField 113 val multiInstanceInvalidation: Boolean = multiInstanceInvalidationServiceIntent != null 114 115 internal var useTempTrackingTable = true 116 117 /** 118 * Creates a database configuration with the given values. 119 * 120 * @param context The application context. 121 * @param name Name of the database, can be null if it is in memory. 122 * @param sqliteOpenHelperFactory The open helper factory to use. 123 * @param migrationContainer The migration container for migrations. 124 * @param callbacks The list of callbacks for database events. 125 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 126 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 127 * @param queryExecutor The Executor used to execute asynchronous queries. 128 * @param requireMigration True if Room should require a valid migration if version changes, 129 * instead of recreating the tables. 130 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 131 * aren't required. 132 */ 133 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 134 @Deprecated("This constructor is deprecated.") 135 constructor( 136 context: Context, 137 name: String?, 138 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 139 migrationContainer: RoomDatabase.MigrationContainer, 140 callbacks: List<RoomDatabase.Callback>?, 141 allowMainThreadQueries: Boolean, 142 journalMode: RoomDatabase.JournalMode, 143 queryExecutor: Executor, 144 requireMigration: Boolean, 145 migrationNotRequiredFrom: Set<Int>? 146 ) : this( 147 context = context, 148 name = name, 149 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 150 migrationContainer = migrationContainer, 151 callbacks = callbacks, 152 allowMainThreadQueries = allowMainThreadQueries, 153 journalMode = journalMode, 154 queryExecutor = queryExecutor, 155 transactionExecutor = queryExecutor, 156 multiInstanceInvalidationServiceIntent = null, 157 allowDestructiveMigrationOnDowngrade = false, 158 requireMigration = requireMigration, 159 migrationNotRequiredFrom = migrationNotRequiredFrom, 160 copyFromAssetPath = null, 161 copyFromFile = null, 162 prepackagedDatabaseCallback = null, 163 copyFromInputStream = null, 164 typeConverters = emptyList(), 165 autoMigrationSpecs = emptyList(), 166 allowDestructiveMigrationForAllTables = false, 167 sqliteDriver = null, 168 queryCoroutineContext = null 169 ) 170 171 /** 172 * Creates a database configuration with the given values. 173 * 174 * @param context The application context. 175 * @param name Name of the database, can be null if it is in memory. 176 * @param sqliteOpenHelperFactory The open helper factory to use. 177 * @param migrationContainer The migration container for migrations. 178 * @param callbacks The list of callbacks for database events. 179 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 180 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 181 * @param queryExecutor The Executor used to execute asynchronous queries. 182 * @param transactionExecutor The Executor used to execute asynchronous transactions. 183 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 184 * @param requireMigration True if Room should require a valid migration if version changes, 185 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 186 * migration is supplied during a downgrade. 187 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 188 * aren't required. 189 */ 190 @OptIn(ExperimentalRoomApi::class) 191 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 192 @Deprecated("This constructor is deprecated.") 193 constructor( 194 context: Context, 195 name: String?, 196 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 197 migrationContainer: RoomDatabase.MigrationContainer, 198 callbacks: List<RoomDatabase.Callback>?, 199 allowMainThreadQueries: Boolean, 200 journalMode: RoomDatabase.JournalMode, 201 queryExecutor: Executor, 202 transactionExecutor: Executor, 203 multiInstanceInvalidation: Boolean, 204 requireMigration: Boolean, 205 allowDestructiveMigrationOnDowngrade: Boolean, 206 migrationNotRequiredFrom: Set<Int>? 207 ) : this( 208 context = context, 209 name = name, 210 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 211 migrationContainer = migrationContainer, 212 callbacks = callbacks, 213 allowMainThreadQueries = allowMainThreadQueries, 214 journalMode = journalMode, 215 queryExecutor = queryExecutor, 216 transactionExecutor = transactionExecutor, 217 multiInstanceInvalidationServiceIntent = 218 if (multiInstanceInvalidation) 219 Intent(context, MultiInstanceInvalidationService::class.java) 220 else null, 221 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 222 requireMigration = requireMigration, 223 migrationNotRequiredFrom = migrationNotRequiredFrom, 224 copyFromAssetPath = null, 225 copyFromFile = null, 226 prepackagedDatabaseCallback = null, 227 copyFromInputStream = null, 228 typeConverters = emptyList(), 229 autoMigrationSpecs = emptyList(), 230 allowDestructiveMigrationForAllTables = false, 231 sqliteDriver = null, 232 queryCoroutineContext = null 233 ) 234 235 /** 236 * Creates a database configuration with the given values. 237 * 238 * @param context The application context. 239 * @param name Name of the database, can be null if it is in memory. 240 * @param sqliteOpenHelperFactory The open helper factory to use. 241 * @param migrationContainer The migration container for migrations. 242 * @param callbacks The list of callbacks for database events. 243 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 244 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 245 * @param queryExecutor The Executor used to execute asynchronous queries. 246 * @param transactionExecutor The Executor used to execute asynchronous transactions. 247 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 248 * @param requireMigration True if Room should require a valid migration if version changes, 249 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 250 * migration is supplied during a downgrade. 251 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 252 * aren't required. 253 * @param copyFromAssetPath The assets path to the pre-packaged database. 254 * @param copyFromFile The pre-packaged database file. 255 */ 256 @OptIn(ExperimentalRoomApi::class) 257 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 258 @Deprecated("This constructor is deprecated.") 259 constructor( 260 context: Context, 261 name: String?, 262 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 263 migrationContainer: RoomDatabase.MigrationContainer, 264 callbacks: List<RoomDatabase.Callback>?, 265 allowMainThreadQueries: Boolean, 266 journalMode: RoomDatabase.JournalMode, 267 queryExecutor: Executor, 268 transactionExecutor: Executor, 269 multiInstanceInvalidation: Boolean, 270 requireMigration: Boolean, 271 allowDestructiveMigrationOnDowngrade: Boolean, 272 migrationNotRequiredFrom: Set<Int>?, 273 copyFromAssetPath: String?, 274 copyFromFile: File? 275 ) : this( 276 context = context, 277 name = name, 278 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 279 migrationContainer = migrationContainer, 280 callbacks = callbacks, 281 allowMainThreadQueries = allowMainThreadQueries, 282 journalMode = journalMode, 283 queryExecutor = queryExecutor, 284 transactionExecutor = transactionExecutor, 285 multiInstanceInvalidationServiceIntent = 286 if (multiInstanceInvalidation) 287 Intent(context, MultiInstanceInvalidationService::class.java) 288 else null, 289 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 290 requireMigration = requireMigration, 291 migrationNotRequiredFrom = migrationNotRequiredFrom, 292 copyFromAssetPath = copyFromAssetPath, 293 copyFromFile = copyFromFile, 294 prepackagedDatabaseCallback = null, 295 copyFromInputStream = null, 296 typeConverters = emptyList(), 297 autoMigrationSpecs = emptyList(), 298 allowDestructiveMigrationForAllTables = false, 299 sqliteDriver = null, 300 queryCoroutineContext = null 301 ) 302 303 /** 304 * Creates a database configuration with the given values. 305 * 306 * @param context The application context. 307 * @param name Name of the database, can be null if it is in memory. 308 * @param sqliteOpenHelperFactory The open helper factory to use. 309 * @param migrationContainer The migration container for migrations. 310 * @param callbacks The list of callbacks for database events. 311 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 312 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 313 * @param queryExecutor The Executor used to execute asynchronous queries. 314 * @param transactionExecutor The Executor used to execute asynchronous transactions. 315 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 316 * @param requireMigration True if Room should require a valid migration if version changes, 317 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 318 * migration is supplied during a downgrade. 319 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 320 * aren't required. 321 * @param copyFromAssetPath The assets path to the pre-packaged database. 322 * @param copyFromFile The pre-packaged database file. 323 * @param copyFromInputStream The callable to get the input stream from which a pre-package 324 * database file will be copied from. 325 */ 326 @OptIn(ExperimentalRoomApi::class) 327 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 328 @Deprecated("This constructor is deprecated.") 329 constructor( 330 context: Context, 331 name: String?, 332 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 333 migrationContainer: RoomDatabase.MigrationContainer, 334 callbacks: List<RoomDatabase.Callback>?, 335 allowMainThreadQueries: Boolean, 336 journalMode: RoomDatabase.JournalMode, 337 queryExecutor: Executor, 338 transactionExecutor: Executor, 339 multiInstanceInvalidation: Boolean, 340 requireMigration: Boolean, 341 allowDestructiveMigrationOnDowngrade: Boolean, 342 migrationNotRequiredFrom: Set<Int>?, 343 copyFromAssetPath: String?, 344 copyFromFile: File?, 345 copyFromInputStream: Callable<InputStream>? 346 ) : this( 347 context = context, 348 name = name, 349 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 350 migrationContainer = migrationContainer, 351 callbacks = callbacks, 352 allowMainThreadQueries = allowMainThreadQueries, 353 journalMode = journalMode, 354 queryExecutor = queryExecutor, 355 transactionExecutor = transactionExecutor, 356 multiInstanceInvalidationServiceIntent = 357 if (multiInstanceInvalidation) 358 Intent(context, MultiInstanceInvalidationService::class.java) 359 else null, 360 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 361 requireMigration = requireMigration, 362 migrationNotRequiredFrom = migrationNotRequiredFrom, 363 copyFromAssetPath = copyFromAssetPath, 364 copyFromFile = copyFromFile, 365 prepackagedDatabaseCallback = null, 366 copyFromInputStream = copyFromInputStream, 367 typeConverters = emptyList(), 368 autoMigrationSpecs = emptyList(), 369 allowDestructiveMigrationForAllTables = false, 370 sqliteDriver = null, 371 queryCoroutineContext = null 372 ) 373 374 /** 375 * Creates a database configuration with the given values. 376 * 377 * @param context The application context. 378 * @param name Name of the database, can be null if it is in memory. 379 * @param sqliteOpenHelperFactory The open helper factory to use. 380 * @param migrationContainer The migration container for migrations. 381 * @param callbacks The list of callbacks for database events. 382 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 383 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 384 * @param queryExecutor The Executor used to execute asynchronous queries. 385 * @param transactionExecutor The Executor used to execute asynchronous transactions. 386 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 387 * @param requireMigration True if Room should require a valid migration if version changes, 388 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 389 * migration is supplied during a downgrade. 390 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 391 * aren't required. 392 * @param copyFromAssetPath The assets path to the pre-packaged database. 393 * @param copyFromFile The pre-packaged database file. 394 * @param copyFromInputStream The callable to get the input stream from which a pre-package 395 * database file will be copied from. 396 * @param prepackagedDatabaseCallback The pre-packaged callback. 397 */ 398 @OptIn(ExperimentalRoomApi::class) 399 @SuppressLint("LambdaLast") 400 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 401 @Deprecated("This constructor is deprecated.") 402 constructor( 403 context: Context, 404 name: String?, 405 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 406 migrationContainer: RoomDatabase.MigrationContainer, 407 callbacks: List<RoomDatabase.Callback>?, 408 allowMainThreadQueries: Boolean, 409 journalMode: RoomDatabase.JournalMode, 410 queryExecutor: Executor, 411 transactionExecutor: Executor, 412 multiInstanceInvalidation: Boolean, 413 requireMigration: Boolean, 414 allowDestructiveMigrationOnDowngrade: Boolean, 415 migrationNotRequiredFrom: Set<Int>?, 416 copyFromAssetPath: String?, 417 copyFromFile: File?, 418 copyFromInputStream: Callable<InputStream>?, 419 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback? 420 ) : this( 421 context = context, 422 name = name, 423 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 424 migrationContainer = migrationContainer, 425 callbacks = callbacks, 426 allowMainThreadQueries = allowMainThreadQueries, 427 journalMode = journalMode, 428 queryExecutor = queryExecutor, 429 transactionExecutor = transactionExecutor, 430 multiInstanceInvalidationServiceIntent = 431 if (multiInstanceInvalidation) 432 Intent(context, MultiInstanceInvalidationService::class.java) 433 else null, 434 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 435 requireMigration = requireMigration, 436 migrationNotRequiredFrom = migrationNotRequiredFrom, 437 copyFromAssetPath = copyFromAssetPath, 438 copyFromFile = copyFromFile, 439 prepackagedDatabaseCallback = prepackagedDatabaseCallback, 440 copyFromInputStream = copyFromInputStream, 441 typeConverters = emptyList(), 442 autoMigrationSpecs = emptyList(), 443 allowDestructiveMigrationForAllTables = false, 444 sqliteDriver = null, 445 queryCoroutineContext = null 446 ) 447 448 /** 449 * Creates a database configuration with the given values. 450 * 451 * @param context The application context. 452 * @param name Name of the database, can be null if it is in memory. 453 * @param sqliteOpenHelperFactory The open helper factory to use. 454 * @param migrationContainer The migration container for migrations. 455 * @param callbacks The list of callbacks for database events. 456 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 457 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 458 * @param queryExecutor The Executor used to execute asynchronous queries. 459 * @param transactionExecutor The Executor used to execute asynchronous transactions. 460 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 461 * @param requireMigration True if Room should require a valid migration if version changes, 462 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 463 * migration is supplied during a downgrade. 464 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 465 * aren't required. 466 * @param copyFromAssetPath The assets path to the pre-packaged database. 467 * @param copyFromFile The pre-packaged database file. 468 * @param copyFromInputStream The callable to get the input stream from which a pre-package 469 * database file will be copied from. 470 * @param prepackagedDatabaseCallback The pre-packaged callback. 471 * @param typeConverters The type converters. 472 */ 473 @OptIn(ExperimentalRoomApi::class) 474 @SuppressLint("LambdaLast") 475 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 476 @Deprecated("This constructor is deprecated.") 477 constructor( 478 context: Context, 479 name: String?, 480 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 481 migrationContainer: RoomDatabase.MigrationContainer, 482 callbacks: List<RoomDatabase.Callback>?, 483 allowMainThreadQueries: Boolean, 484 journalMode: RoomDatabase.JournalMode, 485 queryExecutor: Executor, 486 transactionExecutor: Executor, 487 multiInstanceInvalidation: Boolean, 488 requireMigration: Boolean, 489 allowDestructiveMigrationOnDowngrade: Boolean, 490 migrationNotRequiredFrom: Set<Int>?, 491 copyFromAssetPath: String?, 492 copyFromFile: File?, 493 copyFromInputStream: Callable<InputStream>?, 494 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback?, 495 typeConverters: List<Any> 496 ) : this( 497 context = context, 498 name = name, 499 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 500 migrationContainer = migrationContainer, 501 callbacks = callbacks, 502 allowMainThreadQueries = allowMainThreadQueries, 503 journalMode = journalMode, 504 queryExecutor = queryExecutor, 505 transactionExecutor = transactionExecutor, 506 multiInstanceInvalidationServiceIntent = 507 if (multiInstanceInvalidation) 508 Intent(context, MultiInstanceInvalidationService::class.java) 509 else null, 510 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 511 requireMigration = requireMigration, 512 migrationNotRequiredFrom = migrationNotRequiredFrom, 513 copyFromAssetPath = copyFromAssetPath, 514 copyFromFile = copyFromFile, 515 prepackagedDatabaseCallback = prepackagedDatabaseCallback, 516 copyFromInputStream = copyFromInputStream, 517 typeConverters = typeConverters, 518 autoMigrationSpecs = emptyList(), 519 allowDestructiveMigrationForAllTables = false, 520 sqliteDriver = null, 521 queryCoroutineContext = null 522 ) 523 524 /** 525 * Creates a database configuration with the given values. 526 * 527 * @param context The application context. 528 * @param name Name of the database, can be null if it is in memory. 529 * @param sqliteOpenHelperFactory The open helper factory to use. 530 * @param migrationContainer The migration container for migrations. 531 * @param callbacks The list of callbacks for database events. 532 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 533 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 534 * @param queryExecutor The Executor used to execute asynchronous queries. 535 * @param transactionExecutor The Executor used to execute asynchronous transactions. 536 * @param multiInstanceInvalidation True if Room should perform multi-instance invalidation. 537 * @param requireMigration True if Room should require a valid migration if version changes, 538 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 539 * migration is supplied during a downgrade. 540 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 541 * aren't required. 542 * @param copyFromAssetPath The assets path to the pre-packaged database. 543 * @param copyFromFile The pre-packaged database file. 544 * @param copyFromInputStream The callable to get the input stream from which a pre-package 545 * database file will be copied from. 546 * @param prepackagedDatabaseCallback The pre-packaged callback. 547 * @param typeConverters The type converters. 548 * @param autoMigrationSpecs The auto migration specs. 549 */ 550 @OptIn(ExperimentalRoomApi::class) 551 @SuppressLint("LambdaLast") 552 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 553 @Deprecated("This constructor is deprecated.") 554 constructor( 555 context: Context, 556 name: String?, 557 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 558 migrationContainer: RoomDatabase.MigrationContainer, 559 callbacks: List<RoomDatabase.Callback>?, 560 allowMainThreadQueries: Boolean, 561 journalMode: RoomDatabase.JournalMode, 562 queryExecutor: Executor, 563 transactionExecutor: Executor, 564 multiInstanceInvalidation: Boolean, 565 requireMigration: Boolean, 566 allowDestructiveMigrationOnDowngrade: Boolean, 567 migrationNotRequiredFrom: Set<Int>?, 568 copyFromAssetPath: String?, 569 copyFromFile: File?, 570 copyFromInputStream: Callable<InputStream>?, 571 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback?, 572 typeConverters: List<Any>, 573 autoMigrationSpecs: List<AutoMigrationSpec> 574 ) : this( 575 context = context, 576 name = name, 577 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 578 migrationContainer = migrationContainer, 579 callbacks = callbacks, 580 allowMainThreadQueries = allowMainThreadQueries, 581 journalMode = journalMode, 582 queryExecutor = queryExecutor, 583 transactionExecutor = transactionExecutor, 584 multiInstanceInvalidationServiceIntent = 585 if (multiInstanceInvalidation) 586 Intent(context, MultiInstanceInvalidationService::class.java) 587 else null, 588 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 589 requireMigration = requireMigration, 590 migrationNotRequiredFrom = migrationNotRequiredFrom, 591 copyFromAssetPath = copyFromAssetPath, 592 copyFromFile = copyFromFile, 593 prepackagedDatabaseCallback = null, 594 copyFromInputStream = copyFromInputStream, 595 typeConverters = typeConverters, 596 autoMigrationSpecs = autoMigrationSpecs, 597 allowDestructiveMigrationForAllTables = false, 598 sqliteDriver = null, 599 queryCoroutineContext = null 600 ) 601 602 /** 603 * Creates a database configuration with the given values. 604 * 605 * @param context The application context. 606 * @param name Name of the database, can be null if it is in memory. 607 * @param sqliteOpenHelperFactory The open helper factory to use. 608 * @param migrationContainer The migration container for migrations. 609 * @param callbacks The list of callbacks for database events. 610 * @param allowMainThreadQueries Whether to allow main thread reads/writes or not. 611 * @param journalMode The journal mode. This has to be either TRUNCATE or WRITE_AHEAD_LOGGING. 612 * @param queryExecutor The Executor used to execute asynchronous queries. 613 * @param transactionExecutor The Executor used to execute asynchronous transactions. 614 * @param multiInstanceInvalidationServiceIntent Intent that should be bound to acquire the 615 * invalidation service or `null` if not used. 616 * @param requireMigration True if Room should require a valid migration if version changes, 617 * @param allowDestructiveMigrationOnDowngrade True if Room should recreate tables if no 618 * migration is supplied during a downgrade. 619 * @param migrationNotRequiredFrom The collection of schema versions from which migrations 620 * aren't required. 621 * @param copyFromAssetPath The assets path to the pre-packaged database. 622 * @param copyFromFile The pre-packaged database file. 623 * @param copyFromInputStream The callable to get the input stream from which a pre-package 624 * database file will be copied from. 625 * @param prepackagedDatabaseCallback The pre-packaged callback. 626 * @param typeConverters The type converters. 627 * @param autoMigrationSpecs The auto migration specs. 628 */ 629 @SuppressLint("LambdaLast") 630 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 631 @Deprecated("This constructor is deprecated.") 632 constructor( 633 context: Context, 634 name: String?, 635 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 636 migrationContainer: RoomDatabase.MigrationContainer, 637 callbacks: List<RoomDatabase.Callback>?, 638 allowMainThreadQueries: Boolean, 639 journalMode: RoomDatabase.JournalMode, 640 queryExecutor: Executor, 641 transactionExecutor: Executor, 642 multiInstanceInvalidationServiceIntent: Intent?, 643 requireMigration: Boolean, 644 allowDestructiveMigrationOnDowngrade: Boolean, 645 migrationNotRequiredFrom: Set<Int>?, 646 copyFromAssetPath: String?, 647 copyFromFile: File?, 648 copyFromInputStream: Callable<InputStream>?, 649 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback?, 650 typeConverters: List<Any>, 651 autoMigrationSpecs: List<AutoMigrationSpec> 652 ) : this( 653 context = context, 654 name = name, 655 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 656 migrationContainer = migrationContainer, 657 callbacks = callbacks, 658 allowMainThreadQueries = allowMainThreadQueries, 659 journalMode = journalMode, 660 queryExecutor = queryExecutor, 661 transactionExecutor = transactionExecutor, 662 multiInstanceInvalidationServiceIntent = multiInstanceInvalidationServiceIntent, 663 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 664 requireMigration = requireMigration, 665 migrationNotRequiredFrom = migrationNotRequiredFrom, 666 copyFromAssetPath = copyFromAssetPath, 667 copyFromFile = copyFromFile, 668 prepackagedDatabaseCallback = null, 669 copyFromInputStream = copyFromInputStream, 670 typeConverters = typeConverters, 671 autoMigrationSpecs = autoMigrationSpecs, 672 allowDestructiveMigrationForAllTables = false, 673 sqliteDriver = null, 674 queryCoroutineContext = null 675 ) 676 677 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) // used in generated code 678 @Deprecated("This constructor is deprecated.") 679 constructor( 680 context: Context, 681 name: String?, 682 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory, 683 migrationContainer: RoomDatabase.MigrationContainer, 684 callbacks: List<RoomDatabase.Callback>?, 685 allowMainThreadQueries: Boolean, 686 journalMode: RoomDatabase.JournalMode, 687 queryExecutor: Executor, 688 transactionExecutor: Executor, 689 multiInstanceInvalidationServiceIntent: Intent?, 690 requireMigration: Boolean, 691 allowDestructiveMigrationOnDowngrade: Boolean, 692 migrationNotRequiredFrom: Set<Int>?, 693 copyFromAssetPath: String?, 694 copyFromFile: File?, 695 copyFromInputStream: Callable<InputStream>?, 696 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback?, 697 typeConverters: List<Any>, 698 autoMigrationSpecs: List<AutoMigrationSpec>, 699 allowDestructiveMigrationForAllTables: Boolean, 700 ) : this( 701 context = context, 702 name = name, 703 sqliteOpenHelperFactory = sqliteOpenHelperFactory, 704 migrationContainer = migrationContainer, 705 callbacks = callbacks, 706 allowMainThreadQueries = allowMainThreadQueries, 707 journalMode = journalMode, 708 queryExecutor = queryExecutor, 709 transactionExecutor = transactionExecutor, 710 multiInstanceInvalidationServiceIntent = multiInstanceInvalidationServiceIntent, 711 allowDestructiveMigrationOnDowngrade = allowDestructiveMigrationOnDowngrade, 712 requireMigration = requireMigration, 713 migrationNotRequiredFrom = migrationNotRequiredFrom, 714 copyFromAssetPath = copyFromAssetPath, 715 copyFromFile = copyFromFile, 716 prepackagedDatabaseCallback = null, 717 copyFromInputStream = copyFromInputStream, 718 typeConverters = typeConverters, 719 autoMigrationSpecs = autoMigrationSpecs, 720 allowDestructiveMigrationForAllTables = allowDestructiveMigrationForAllTables, 721 sqliteDriver = null, 722 queryCoroutineContext = null 723 ) 724 725 /** 726 * Returns whether a migration is required from the specified version. 727 * 728 * @param version The schema version. 729 * @return True if a valid migration is required, false otherwise. 730 */ 731 @Deprecated( 732 """Use [isMigrationRequired(int, int)] which takes 733 [allowDestructiveMigrationOnDowngrade] into account.""", 734 ReplaceWith("isMigrationRequired(version, version + 1)") 735 ) isMigrationRequiredFromnull736 open fun isMigrationRequiredFrom(version: Int): Boolean { 737 return isMigrationRequired(version, version + 1) 738 } 739 740 /** 741 * Returns whether a migration is required between two versions. 742 * 743 * @param fromVersion The old schema version. 744 * @param toVersion The new schema version. 745 * @return True if a valid migration is required, false otherwise. 746 */ isMigrationRequirednull747 open fun isMigrationRequired(fromVersion: Int, toVersion: Int): Boolean { 748 return isMigrationRequiredExt(fromVersion, toVersion) 749 } 750 751 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) copynull752 fun copy( 753 context: Context = this.context, 754 name: String? = this.name, 755 sqliteOpenHelperFactory: SupportSQLiteOpenHelper.Factory? = this.sqliteOpenHelperFactory, 756 migrationContainer: RoomDatabase.MigrationContainer = this.migrationContainer, 757 callbacks: List<RoomDatabase.Callback>? = this.callbacks, 758 allowMainThreadQueries: Boolean = this.allowMainThreadQueries, 759 journalMode: RoomDatabase.JournalMode = this.journalMode, 760 queryExecutor: Executor = this.queryExecutor, 761 transactionExecutor: Executor = this.transactionExecutor, 762 multiInstanceInvalidationServiceIntent: Intent? = 763 this.multiInstanceInvalidationServiceIntent, 764 requireMigration: Boolean = this.requireMigration, 765 allowDestructiveMigrationOnDowngrade: Boolean = this.allowDestructiveMigrationOnDowngrade, 766 migrationNotRequiredFrom: Set<Int>? = this.migrationNotRequiredFrom, 767 copyFromAssetPath: String? = this.copyFromAssetPath, 768 copyFromFile: File? = this.copyFromFile, 769 copyFromInputStream: Callable<InputStream>? = this.copyFromInputStream, 770 prepackagedDatabaseCallback: RoomDatabase.PrepackagedDatabaseCallback? = 771 this.prepackagedDatabaseCallback, 772 typeConverters: List<Any> = this.typeConverters, 773 autoMigrationSpecs: List<AutoMigrationSpec> = this.autoMigrationSpecs, 774 allowDestructiveMigrationForAllTables: Boolean = this.allowDestructiveMigrationForAllTables, 775 sqliteDriver: SQLiteDriver? = this.sqliteDriver, 776 queryCoroutineContext: CoroutineContext? = this.queryCoroutineContext 777 ) = 778 DatabaseConfiguration( 779 context, 780 name, 781 sqliteOpenHelperFactory, 782 migrationContainer, 783 callbacks, 784 allowMainThreadQueries, 785 journalMode, 786 queryExecutor, 787 transactionExecutor, 788 multiInstanceInvalidationServiceIntent, 789 requireMigration, 790 allowDestructiveMigrationOnDowngrade, 791 migrationNotRequiredFrom, 792 copyFromAssetPath, 793 copyFromFile, 794 copyFromInputStream, 795 prepackagedDatabaseCallback, 796 typeConverters, 797 autoMigrationSpecs, 798 allowDestructiveMigrationForAllTables, 799 sqliteDriver, 800 queryCoroutineContext 801 ) 802 } 803