英文:
How can I know if RoomDatabase.clearAllTables() has finished?
问题
RoomDatabase#clearAllTables()
返回 Unit
。那么,如何知道它何时完成?是否可能?
更新:这是从 AppDatabase_Impl.java
中生成的代码
@Override
public void clearAllTables() {
super.assertNotMainThread();
final SupportSQLiteDatabase _db = super.getOpenHelper().getWritableDatabase();
boolean _supportsDeferForeignKeys = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP;
try {
if (!_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA foreign_keys = FALSE");
}
super.beginTransaction();
if (_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA defer_foreign_keys = TRUE");
}
_db.execSQL("DELETE FROM `something`");
_db.execSQL("DELETE FROM `something2`");
super.setTransactionSuccessful();
} finally {
super.endTransaction();
if (!_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA foreign_keys = TRUE");
}
_db.query("PRAGMA wal_checkpoint(FULL)").close();
if (!_db.inTransaction()) {
_db.execSQL("VACUUM");
}
}
}
英文:
RoomDatabase#clearAllTables()
returns Unit
. So, how can one know when it has finished? Is that possible at all?
Update: That is the generated code taken from AppDatabase_Impl.java
@Override
public void clearAllTables() {
super.assertNotMainThread();
final SupportSQLiteDatabase _db = super.getOpenHelper().getWritableDatabase();
boolean _supportsDeferForeignKeys = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP;
try {
if (!_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA foreign_keys = FALSE");
}
super.beginTransaction();
if (_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA defer_foreign_keys = TRUE");
}
_db.execSQL("DELETE FROM `something`");
_db.execSQL("DELETE FROM `something2`");
super.setTransactionSuccessful();
} finally {
super.endTransaction();
if (!_supportsDeferForeignKeys) {
_db.execSQL("PRAGMA foreign_keys = TRUE");
}
_db.query("PRAGMA wal_checkpoint(FULL)").close();
if (!_db.inTransaction()) {
_db.execSQL("VACUUM");
}
}
}
答案1
得分: 1
The generated code for clearAllTables()
is synchronous. You can see from the generated code in your question that the function implements the database transaction and deletes the contents of the tables directly within that function. All of the functions called on _db
, such as execSQL()
, are synchronous.
英文:
The generated code for clearAllTables()
is synchronous. You can see from the generated code in your question that the function implements the database transaction and deletes the contents of the tables directly within that function. All of the functions called on _db
, such as execSQL()
, are synchronous.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论