本文整理匯總了Java中android.arch.persistence.room.RoomDatabase類的典型用法代碼示例。如果您正苦於以下問題:Java RoomDatabase類的具體用法?Java RoomDatabase怎麽用?Java RoomDatabase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RoomDatabase類屬於android.arch.persistence.room包,在下文中一共展示了RoomDatabase類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: obtainRoomDatabase
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
@Override
public <DB extends RoomDatabase> DB obtainRoomDatabase(Class<DB> database, String dbName) {
if (mRoomDatabaseCache == null) {
mRoomDatabaseCache = mCacheFactory.build(CacheType.ROOM_DATABASE_CACHE_TYPE);
}
Preconditions.checkNotNull(mRoomDatabaseCache, "Cannot return null from a Cache.Factory#build(int) method");
DB roomDatabase;
synchronized (mRoomDatabaseCache) {
roomDatabase = (DB) mRoomDatabaseCache.get(database.getName());
if (roomDatabase == null) {
RoomDatabase.Builder builder = Room.databaseBuilder(mApplication, database, dbName);
//Customize the room configuration
if (mRoomConfiguration != null) {
mRoomConfiguration.configRoom(mApplication, builder);
}
roomDatabase = (DB) builder.build();
mRoomDatabaseCache.put(database.getName(), roomDatabase);
}
}
return roomDatabase;
}
示例2: obtainRoomDatabase
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
@Override
public <DB extends RoomDatabase> DB obtainRoomDatabase(Class<DB> database, String dbName) {
if (mRoomDatabaseCache == null) {
mRoomDatabaseCache = mCacheFactory.build(CacheType.ROOM_DATABASE_CACHE_TYPE);
}
Preconditions.checkNotNull(mRoomDatabaseCache, "Cannot return null from a Cache.Factory#build(int) method");
DB roomDatabase;
synchronized (mRoomDatabaseCache) {
roomDatabase = (DB) mRoomDatabaseCache.get(database.getName());
if (roomDatabase == null) {
RoomDatabase.Builder builder = Room.databaseBuilder(mApplication, database, dbName);
//自定義 Room 配置
if (mRoomConfiguration != null) {
mRoomConfiguration.configRoom(mApplication, builder);
}
roomDatabase = (DB) builder.build();
mRoomDatabaseCache.put(database.getName(), roomDatabase);
}
}
return roomDatabase;
}
示例3: reopenDatabase
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
public void reopenDatabase() {
if (appDB != null) {
appDB.close();
}
appDB = Room.databaseBuilder(context, AppDatabase.class, "openScale.db")
.allowMainThreadQueries()
.addCallback(new RoomDatabase.Callback() {
@Override
public void onOpen(SupportSQLiteDatabase db) {
super.onOpen(db);
db.setForeignKeyConstraintsEnabled(true);
}
})
.addMigrations(AppDatabase.MIGRATION_1_2)
.build();
measurementDAO = appDB.measurementDAO();
userDAO = appDB.userDAO();
}
示例4: obtainRoomDatabase
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
/**
* Obtain the corresponding RxCache service according to the incoming Class
*
* @param database RoomDatabase Class
* @param <DB> RoomDatabase
* @param dbName RoomDatabase Name
* @return RoomDatabase
*/
<DB extends RoomDatabase> DB obtainRoomDatabase(Class<DB> database, String dbName);
示例5: configRoom
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {
}
示例6: obtainRoomDatabase
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
/**
* 根據傳入的 Class 獲取對應的 RxCache service
*
* @param database RoomDatabase Class
* @param <DB> RoomDatabase
* @param dbName RoomDatabase name
* @return RoomDatabase
*/
<DB extends RoomDatabase> DB obtainRoomDatabase(Class<DB> database, String dbName);
示例7: configRoom
import android.arch.persistence.room.RoomDatabase; //導入依賴的package包/類
/**
* 提供接口,自定義配置 RoomDatabase
*
* @param context Context
* @param builder RoomDatabase.Builder
*/
void configRoom(Context context, RoomDatabase.Builder<DB> builder);