本文整理汇总了Java中android.arch.persistence.room.RoomDatabase.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java RoomDatabase.Builder方法的具体用法?Java RoomDatabase.Builder怎么用?Java RoomDatabase.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.arch.persistence.room.RoomDatabase
的用法示例。
在下文中一共展示了RoomDatabase.Builder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: configRoom
import android.arch.persistence.room.RoomDatabase; //导入方法依赖的package包/类
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {
}
示例4: configRoom
import android.arch.persistence.room.RoomDatabase; //导入方法依赖的package包/类
/**
* 提供接口,自定义配置 RoomDatabase
*
* @param context Context
* @param builder RoomDatabase.Builder
*/
void configRoom(Context context, RoomDatabase.Builder<DB> builder);