Created
May 29, 2018 18:09
-
-
Save mibrahimdev/98c7b2670dacd9c7340fcf16ed0a8225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = { WeatherEntry.class , UserEntry.class}, version = 2) | |
//any change to tables .. you must increase version, and define a migration methodology | |
@TypeConverters(DateConverter.class) | |
public abstract class SunshineDatabase extends RoomDatabase { | |
... | |
public static SunshineDatabase getInstance(Context context) { | |
if (sInstance == null) { | |
synchronized (LOCK) { | |
if (sInstance == null) { | |
sInstance = Room.databaseBuilder(context.getApplicationContext(), SunshineDatabase.class, | |
SunshineDatabase.DATABASE_NAME) | |
.fallbackToDestructiveMigration() //recreate all tables | |
.build(); | |
} | |
} | |
} | |
return sInstance; | |
} | |
public abstract WeatherDao weatherDao(); | |
//this is another Dao, I created to experiment | |
// if It's needed to create a Room database for each DAO | |
//well nope, but you need to define your entities in @Database(Class[] entities) | |
public abstract UserDao userDao(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment