Java 类android.arch.persistence.room.RoomDatabase 实例源码

项目:GmArchMvvm    文件:RepositoryManager.java   
@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;
}
项目:MVVMArms    文件:RepositoryManager.java   
@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;
}
项目:openScale    文件:OpenScale.java   
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();
}
项目:GmArchMvvm    文件:IRepositoryManager.java   
/**
 * 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);
项目:GmArchMvvm    文件:DatabaseModule.java   
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {

}
项目:GmArchMvvm    文件:DatabaseModule.java   
/**
 * Provide interface, custom configuration RoomDatabase
 *
 * @param context Context
 * @param builder RoomDatabase.Builder
 */
void configRoom(Context context, RoomDatabase.Builder<DB> builder);
项目:MVVMArms    文件:IRepositoryManager.java   
/**
 * 根据传入的 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);
项目:MVVMArms    文件:DatabaseModule.java   
/**
 * 提供接口,自定义配置 RoomDatabase
 *
 * @param context Context
 * @param builder RoomDatabase.Builder
 */
void configRoom(Context context, RoomDatabase.Builder<DB> builder);
项目:MVVMArms    文件:DatabaseModule.java   
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {

}