android.arch.persistence.room.RoomDatabase Java Examples

The following examples show how to use android.arch.persistence.room.RoomDatabase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryManager.java    From MVVMArms with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: IRepositoryManager.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
/**
 * 根据传入的 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);
 
Example #3
Source File: DatabaseModule.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
/**
 * 提供接口,自定义配置 RoomDatabase
 *
 * @param context Context
 * @param builder RoomDatabase.Builder
 */
void configRoom(Context context, RoomDatabase.Builder<DB> builder);
 
Example #4
Source File: DatabaseModule.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {

}