RoomDatabase
abstract class RoomDatabase
kotlin.Any | |
↳ | androidx.room.RoomDatabase |
Base class for all Room databases. All classes that are annotated with Database
must extend this class.
RoomDatabase provides direct access to the underlying database implementation but you should prefer using Dao
classes.
Summary
Nested classes | |
---|---|
open |
Builder for RoomDatabase. |
abstract |
Callback for |
Journal modes for SQLite database. |
|
open |
A container to hold migrations. |
abstract |
Callback for |
abstract |
Callback interface for when SQLite queries are executed. |
Public constructors | |
---|---|
<init>() Creates a RoomDatabase. |
Public methods | |
---|---|
open Unit |
Wrapper for |
abstract Unit |
Deletes all rows from all the tables that are registered to this database as |
open Unit |
close() Closes the database if it is already open. |
open SupportSQLiteStatement! |
compileStatement(@NonNull sql: String) Wrapper for |
open Unit |
Wrapper for |
open InvalidationTracker |
Returns the invalidation tracker for this database. |
open SupportSQLiteOpenHelper |
Returns the SQLite open helper used by this database. |
open Executor | |
open Executor | |
open T? |
getTypeConverter(@NonNull klass: Class<T>) Gets the instance of the given Type Converter. |
open Boolean |
Returns true if current thread is in a transaction. |
open Unit |
init(@NonNull configuration: DatabaseConfiguration) Called by |
open Boolean |
isOpen() Returns true if database connection is open and initialized. |
open Cursor |
Convenience method to query the database with arguments. |
open Cursor |
query(@NonNull query: SupportSQLiteQuery) Wrapper for |
open Cursor |
query(@NonNull query: SupportSQLiteQuery, @Nullable signal: CancellationSignal?) Wrapper for |
open Unit |
runInTransaction(@NonNull body: Runnable) Executes the specified |
open V |
runInTransaction(@NonNull body: Callable<V>) Executes the specified |
open Unit |
Wrapper for |
Protected methods | |
---|---|
abstract InvalidationTracker |
Called when the RoomDatabase is created. |
abstract SupportSQLiteOpenHelper |
createOpenHelper(config: DatabaseConfiguration!) Creates the open helper to access the database. |
open MutableMap<Class<*>!, MutableList<Class<*>!>!> |
Returns a Map of String -> List<Class> where each entry has the `key` as the DAO name and `value` as the list of type converter classes that are necessary for the database to function. |
open Unit |
internalInitInvalidationTracker(@NonNull db: SupportSQLiteDatabase) Called by the generated code when database is open. |
Extension functions | ||
---|---|---|
From androidx.room
|
Properties | |
---|---|
SupportSQLiteDatabase! |
Set by the generated open helper. |
Public constructors
<init>
RoomDatabase()
Creates a RoomDatabase.
You cannot create an instance of a database, instead, you should acquire it via Room#databaseBuilder(Context, Class, String)
or Room#inMemoryDatabaseBuilder(Context, Class)
.
Public methods
beginTransaction
open funbeginTransaction(): Unit
Deprecated: Use runInTransaction(Runnable)
Wrapper for SupportSQLiteDatabase#beginTransaction()
.
clearAllTables
@WorkerThread abstract fun clearAllTables(): Unit
Deletes all rows from all the tables that are registered to this database as Database#entities()
.
This does NOT reset the auto-increment value generated by PrimaryKey#autoGenerate()
.
After deleting the rows, Room will set a WAL checkpoint and run VACUUM. This means that the data is completely erased. The space will be reclaimed by the system if the amount surpasses the threshold of database file size.
See Also
compileStatement
open fun compileStatement(@NonNull sql: String): SupportSQLiteStatement!
Wrapper for SupportSQLiteDatabase#compileStatement(String)
.
Parameters | |
---|---|
sql |
String: The query to compile. |
Return | |
---|---|
SupportSQLiteStatement! |
The compiled query. |
endTransaction
open funendTransaction(): Unit
Deprecated: Use runInTransaction(Runnable)
Wrapper for SupportSQLiteDatabase#endTransaction()
.
getInvalidationTracker
@NonNull open fun getInvalidationTracker(): InvalidationTracker
Returns the invalidation tracker for this database.
You can use the invalidation tracker to get notified when certain tables in the database are modified.
Return | |
---|---|
InvalidationTracker |
The invalidation tracker for the database. |
getOpenHelper
@NonNull open fun getOpenHelper(): SupportSQLiteOpenHelper
Returns the SQLite open helper used by this database.
Return | |
---|---|
SupportSQLiteOpenHelper |
The SQLite open helper used by this database. |
getQueryExecutor
@NonNull open fun getQueryExecutor(): Executor
Return | |
---|---|
Executor |
The Executor in use by this database for async queries. |
getTransactionExecutor
@NonNull open fun getTransactionExecutor(): Executor
Return | |
---|---|
Executor |
The Executor in use by this database for async transactions. |
getTypeConverter
@Nullable open fun <T : Any!> getTypeConverter(@NonNull klass: Class<T>): T?
Gets the instance of the given Type Converter.
Parameters | |
---|---|
klass |
Class<T>: The Type Converter class. |
<T> |
The type of the expected Type Converter subclass. |
Return | |
---|---|
T? |
An instance of T if it is provided in the builder. |
inTransaction
open fun inTransaction(): Boolean
Returns true if current thread is in a transaction.
Return | |
---|---|
Boolean |
True if there is an active transaction in current thread, false otherwise. |
init
@CallSuper open fun init(@NonNull configuration: DatabaseConfiguration): Unit
Called by Room
when it is initialized.
Parameters | |
---|---|
configuration |
DatabaseConfiguration: The database configuration. |
isOpen
open fun isOpen(): Boolean
Returns true if database connection is open and initialized.
Return | |
---|---|
|