當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。