当前位置: 首页>>代码示例>>Java>>正文


Java RoomDatabase类代码示例

本文整理汇总了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;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:22,代码来源:RepositoryManager.java

示例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;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:22,代码来源:RepositoryManager.java

示例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();
}
 
开发者ID:oliexdev,项目名称:openScale,代码行数:20,代码来源:OpenScale.java

示例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);
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:10,代码来源:IRepositoryManager.java

示例5: configRoom

import android.arch.persistence.room.RoomDatabase; //导入依赖的package包/类
@Override
public void configRoom(Context context, RoomDatabase.Builder builder) {

}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:5,代码来源:DatabaseModule.java

示例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);
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:10,代码来源:IRepositoryManager.java

示例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);
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:8,代码来源:DatabaseModule.java


注:本文中的android.arch.persistence.room.RoomDatabase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。