private static AppDatabase getDatabase(Context context) { return Room .databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME) .addMigrations(MIGRATION_11_12) .fallbackToDestructiveMigration() .build(); }
private static LogDatabase initialize(Context context) { sInstance = Room.databaseBuilder(context.getApplicationContext(), LogDatabase.class, "log-database").fallbackToDestructiveMigration().build(); return sInstance; }
@Override public void onCreate() { super.onCreate(); // when upgrading versions, kill the original tables by using // fallbackToDestructiveMigration() myDatabase = Room.databaseBuilder(this, MyDatabase.class, MyDatabase.NAME).fallbackToDestructiveMigration().build(); // use chrome://inspect to inspect your SQL database Stetho.initializeWithDefaults(this); }
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; }
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; }
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 AppDatabase getDatabase(Context context) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context, AppDatabase.class, "tasks") //Room.inMemoryDatabaseBuilder(context.getApplicationContext(), AppDatabase.class) // To simplify the exercise, allow queries on the main thread. // Don't do this on a real app! .allowMainThreadQueries() // recreate the database if necessary .fallbackToDestructiveMigration() .build(); } return INSTANCE; }
@Override public void onCreate() { super.onCreate(); appDatabase = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "gsoc-database") .fallbackToDestructiveMigration() .build(); }
private static SampleDatabase buildDb(final Context context) { return Room.databaseBuilder(context, SampleDatabase.class, SampleDatabase.NAME) .fallbackToDestructiveMigration() //Pre-populating database with some sample data .addCallback(new RoomDatabase.Callback() { @Override public void onCreate(@NonNull final SupportSQLiteDatabase db) { super.onCreate(db); new Thread(new Runnable() { @Override public void run() { getInstance(context).getUserDao() .insert(createSampleRecords()); } }) .start(); } }) .build(); }