public static AppDatabase getInstance(Context context) { if (sInstance == null) { synchronized (LOCK) { Log.d(LOG_TAG, "Creating new database instance"); sInstance = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, AppDatabase.DATABASE_NAME) // TODO (1) Disable queries on main thread // Queries should be done in a separate thread to avoid locking the UI // We will allow this ONLY TEMPORALLY to see that our DB is working .allowMainThreadQueries() .build(); } } Log.d(LOG_TAG, "Getting the database instance"); return sInstance; }
private static AppDatabase getDatabase(Context context) { return Room .databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME) .addMigrations(MIGRATION_11_12) .fallbackToDestructiveMigration() .build(); }
sInstance = Room.databaseBuilder(context.getApplicationContext(), AutofillDatabase.class, "AutofillSample.db") .addCallback(new RoomDatabase.Callback() { @Override public void onCreate(@NonNull SupportSQLiteDatabase db) { .build();
static CityDatabase create(Context ctxt, final boolean applyPragmas) { RoomDatabase.Builder<CityDatabase> b= Room.databaseBuilder(ctxt.getApplicationContext(), CityDatabase.class, DB_NAME); if (applyPragmas) { b.addCallback(new Callback() { @Override public void onCreate(@NonNull SupportSQLiteDatabase db) { super.onCreate(db); db.query("PRAGMA journal_mode = MEMORY"); } @Override public void onOpen(@NonNull SupportSQLiteDatabase db) { super.onOpen(db); db.query("PRAGMA synchronous = OFF"); } }); } return(b.build()); } }
public static AppDatabase getAppDatabase(Context context) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "adhell-database") .addMigrations(MIGRATION_14_15) .addMigrations(MIGRATION_15_16) .addMigrations(MIGRATION_16_17) .addMigrations(MIGRATION_17_18) .addMigrations(MIGRATION_18_19) .addMigrations(MIGRATION_19_20) .addMigrations(MIGRATION_20_21) .addMigrations(MIGRATION_21_22) .build(); } return INSTANCE; }
public static AppRoomDatabase getInstance(Context context) { if (instance == null) { synchronized (AppRoomDatabase.class) { instance = Room.databaseBuilder(context, AppRoomDatabase.class, "tvhclient") .addMigrations(MIGRATION_1_2) .addMigrations(MIGRATION_2_3) .addMigrations(MIGRATION_3_4) .addMigrations(MIGRATION_4_5) .addMigrations(MIGRATION_5_6) .addMigrations(MIGRATION_6_7) .addMigrations(MIGRATION_7_8) .addMigrations(MIGRATION_8_9) .addMigrations(MIGRATION_9_10) .build(); } } return instance; }
static WordRoomDatabase getDatabase(final Context context) { if (INSTANCE == null) { synchronized (WordRoomDatabase.class) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase.class, "word_database") // Wipes and rebuilds instead of migrating if no Migration object. // Migration is not part of this codelab. .fallbackToDestructiveMigration() .addCallback(sRoomDatabaseCallback) .build(); } } } return INSTANCE; }
public static WordRoomDatabase getDatabase(final Context context) { if (INSTANCE == null) { synchronized (WordRoomDatabase.class) { if (INSTANCE == null) { // Create database here. INSTANCE = Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase.class, "word_database") // Wipes and rebuilds instead of migrating if no Migration object. // Migration is not part of this practical. .fallbackToDestructiveMigration() .addCallback(sRoomDatabaseCallback) .build(); } } } return INSTANCE; }
@Provides @Singleton WeatherDAO provideWeatherDAO() { AppDatabase database = Room.databaseBuilder(context, AppDatabase.class, "data") //.addMigrations(MIGRATION_1_2) .build(); // If no database found on the device, a new one created via analysing Entity interfaces. // Migrations aren't executed even when required schema version > 1. // It means migrations can't be used for populating db with data. // Hope they change this behaviour. Executors.newSingleThreadExecutor().execute(() -> { init(database.weatherDao()); }); return database.weatherDao(); }
/** * Returns the mesh database */ @RestrictTo(RestrictTo.Scope.LIBRARY) static MeshNetworkDb getDatabase(final Context context) { if (INSTANCE == null) { synchronized (MeshNetworkDb.class) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), MeshNetworkDb.class, "mesh_network_database.db") .addCallback(sRoomDatabaseCallback) .build(); } } } return INSTANCE; }
public static WordRoomDatabase getDatabase(final Context context) { if (INSTANCE == null) { synchronized (WordRoomDatabase.class) { if (INSTANCE == null) { // Create database here INSTANCE = Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase.class, "word_database") // Wipes and rebuilds instead of migrating if no Migration object. // Migration is not part of this practical. .fallbackToDestructiveMigration() .addCallback(sRoomDatabaseCallback) .build(); } } } return INSTANCE; }
private static BookDatabase create(Context ctxt) { RoomDatabase.Builder<BookDatabase> b= Room.databaseBuilder(ctxt.getApplicationContext(), BookDatabase.class, DB_NAME); b.addCallback(new Callback() { @Override public void onCreate(@NonNull SupportSQLiteDatabase db) { super.onCreate(db); db.execSQL("CREATE VIRTUAL TABLE booksearch USING fts4(sequence, prose)"); } }); BookDatabase books=b.build(); populate(ctxt, books); return books; }
public void init(Context context) { db = Room.databaseBuilder(context.getApplicationContext(), DB.class, DATABASE_NAME).build(); }
public void init(Context context) { db = Room.databaseBuilder(context.getApplicationContext(), DB.class, DATABASE_NAME).build(); }
public void init(Context context) { db = Room.databaseBuilder(context.getApplicationContext(), DB.class, DATABASE_NAME).build(); }
@Before public void setup() { // using an in-memory database for testing, since it doesn't survive killing the process mDatabase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), AutofillDatabase.class) .build(); AutofillDao tasksDao = mDatabase.autofillDao(); SharedPreferences sharedPreferences = InstrumentationRegistry.getContext() .getSharedPreferences(LocalAutofillDataSource.SHARED_PREF_KEY, Context.MODE_PRIVATE); // Make sure that we're not keeping a reference to the wrong instance. LocalAutofillDataSource.clearInstance(); mLocalDataSource = LocalAutofillDataSource.getInstance(sharedPreferences, tasksDao, new SingleExecutors()); }
public void init(Context context) { db = Room.databaseBuilder(context.getApplicationContext(), DB.class, DATABASE_NAME).build(); }
static WordRoomDatabase getDatabase(final Context context) { if (INSTANCE == null) { synchronized (WordRoomDatabase.class) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), WordRoomDatabase.class, "word_database") // Wipes and rebuilds instead of migrating if no Migration object. // Migration is not part of this codelab. .fallbackToDestructiveMigration() .addCallback(sRoomDatabaseCallback) .build(); } } } return INSTANCE; }
static TripDatabase create(Context ctxt, String name, boolean memoryOnly) { RoomDatabase.Builder<TripDatabase> b; if (memoryOnly) { b=Room.inMemoryDatabaseBuilder(ctxt.getApplicationContext(), TripDatabase.class); } else { b=Room.databaseBuilder(ctxt.getApplicationContext(), TripDatabase.class, name); } return(b.addMigrations(Migrations.FROM_1_TO_2).build()); } }
static TripDatabase create(Context ctxt, boolean memoryOnly) { RoomDatabase.Builder<TripDatabase> b; if (memoryOnly) { b=Room.inMemoryDatabaseBuilder(ctxt.getApplicationContext(), TripDatabase.class); } else { b=Room.databaseBuilder(ctxt.getApplicationContext(), TripDatabase.class, DB_NAME); } return(b.build()); } }