belongs to Maven artifact android.arch.persistence.room:runtime:1.1.0-beta2
RoomDatabase
public
abstract
class
RoomDatabase
extends Object
java.lang.Object | |
↳ | android.arch.persistence.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.
See also:
Summary
Nested classes | |
---|---|
class |
RoomDatabase.Builder<T extends RoomDatabase>
Builder for RoomDatabase. |
class |
RoomDatabase.Callback
Callback for |
enum |
RoomDatabase.JournalMode
Journal modes for SQLite database. |
class |
RoomDatabase.MigrationContainer
A container to hold migrations. |
Fields | |
---|---|
protected
List<RoomDatabase.Callback> |
mCallbacks
|
protected
SupportSQLiteDatabase |
mDatabase
|
Public constructors | |
---|---|
RoomDatabase()
Creates a RoomDatabase. |
Public methods | |
---|---|
void
|
beginTransaction()
Wrapper for |
abstract
void
|
clearAllTables()
Deletes all rows from all the tables that are registered to this database as
|
void
|
close()
Closes the database if it is already open. |
SupportSQLiteStatement
|
compileStatement(String sql)
Wrapper for |
void
|
endTransaction()
Wrapper for |
InvalidationTracker
|
getInvalidationTracker()
Returns the invalidation tracker for this database. |
SupportSQLiteOpenHelper
|
getOpenHelper()
Returns the SQLite open helper used by this database. |
boolean
|
inTransaction()
Returns true if current thread is in a transaction. |
void
|
init(DatabaseConfiguration configuration)
Called by |
boolean
|
isOpen()
Returns true if database connection is open and initialized. |
Cursor
|
query(SupportSQLiteQuery query)
Wrapper for |
Cursor
|
query(String query, Object[] args)
Convenience method to query the database with arguments. |
<V>
V
|
runInTransaction(Callable<V> body)
Executes the specified |
void
|
runInTransaction(Runnable body)
Executes the specified |
void
|
setTransactionSuccessful()
Wrapper for |
Protected methods | |
---|---|
abstract
InvalidationTracker
|
createInvalidationTracker()
Called when the RoomDatabase is created. |
abstract
SupportSQLiteOpenHelper
|
createOpenHelper(DatabaseConfiguration config)
Creates the open helper to access the database. |
void
|
internalInitInvalidationTracker(SupportSQLiteDatabase db)
Called by the generated code when database is open. |
Inherited methods | |
---|---|
Fields
Public constructors
RoomDatabase
RoomDatabase ()
Creates a RoomDatabase.
You cannot create an instance of a database, instead, you should acquire it via
databaseBuilder(Context, Class, String)
or
inMemoryDatabaseBuilder(Context, Class)
.
Public methods
clearAllTables
void clearAllTables ()
Deletes all rows from all the tables that are registered to this database as
entities()
.
This does NOT reset the auto-increment value generated by 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
SupportSQLiteStatement compileStatement (String sql)
Wrapper for compileStatement(String)
.
Parameters | |
---|---|
sql |
String : The query to compile. |
Returns | |
---|---|
SupportSQLiteStatement |
The compiled query. |
getInvalidationTracker
InvalidationTracker getInvalidationTracker ()
Returns the invalidation tracker for this database.
You can use the invalidation tracker to get notified when certain tables in the database are modified.
Returns | |
---|---|
InvalidationTracker |
The invalidation tracker for the database. |
getOpenHelper
SupportSQLiteOpenHelper getOpenHelper ()
Returns the SQLite open helper used by this database.
Returns | |
---|---|
SupportSQLiteOpenHelper |
The SQLite open helper used by this database. |
inTransaction
boolean inTransaction ()
Returns true if current thread is in a transaction.
Returns | |
---|---|
boolean |
True if there is an active transaction in current thread, false otherwise. |
See also:
init
void init (DatabaseConfiguration configuration)
Called by Room
when it is initialized.
Parameters | |
---|---|
configuration |
DatabaseConfiguration : The database configuration.
|
isOpen
boolean isOpen ()
Returns true if database connection is open and initialized.
Returns | |
---|---|
boolean |
true if the database connection is open, false otherwise. |
query
Cursor query (SupportSQLiteQuery query)
Wrapper for query(SupportSQLiteQuery)
.
Parameters | |
---|---|
query |
SupportSQLiteQuery : The Query which includes the SQL and a bind callback for bind arguments. |
Returns | |
---|---|
Cursor |
Result of the query. |
query
Cursor query (String query, Object[] args)
Convenience method to query the database with arguments.
Parameters | |
---|---|
query |
String : The sql query |
args |
Object : The bind arguments for the placeholders in the query |
Returns | |
---|---|
Cursor |
A Cursor obtained by running the given query in the Room database. |
runInTransaction
V runInTransaction (Callable<V> body)
Executes the specified Callable
in a database transaction. The transaction will be
marked as successful unless an exception is thrown in the Callable
.
Parameters | |
---|---|
body |
Callable : The piece of code to execute. |
Returns | |
---|---|
V |
The value returned from the Callable .
|
runInTransaction
void runInTransaction (Runnable body)
Executes the specified Runnable
in a database transaction. The transaction will be
marked as successful unless an exception is thrown in the Runnable
.
Parameters | |
---|---|
body |
Runnable : The piece of code to execute.
|
setTransactionSuccessful
void setTransactionSuccessful ()
Wrapper for setTransactionSuccessful()
.
Protected methods
createInvalidationTracker
InvalidationTracker createInvalidationTracker ()
Called when the RoomDatabase is created.
This is already implemented by the generated code.
Returns | |
---|---|
InvalidationTracker |
Creates a new InvalidationTracker. |
createOpenHelper
SupportSQLiteOpenHelper createOpenHelper (DatabaseConfiguration config)
Creates the open helper to access the database. Generated class already implements this method. Note that this method is called when the RoomDatabase is initialized.
Parameters | |
---|---|
config |
DatabaseConfiguration : The configuration of the Room database. |
Returns | |
---|---|
SupportSQLiteOpenHelper |
A new SupportSQLiteOpenHelper to be used while connecting to the database. |
internalInitInvalidationTracker
void internalInitInvalidationTracker (SupportSQLiteDatabase db)
Called by the generated code when database is open.
You should never call this method manually.
Parameters | |
---|---|
db |
SupportSQLiteDatabase : The database instance.
|
Annotations
Classes
Enums
Exceptions
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.