Created
July 31, 2017 01:31
-
-
Save mwshubham/dc04065c98f842ab76b1e927b6c4e450 to your computer and use it in GitHub Desktop.
AppDatabase
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 = {CategoryData.class}, version = DATABASE_VERSION) | |
public abstract class AppDatabase extends RoomDatabase { | |
private static AppDatabase INSTANCE; | |
/*Database Constant*/ | |
@SuppressWarnings("WeakerAccess") | |
public final static int DATABASE_VERSION = 1; | |
public final static String DATABASE_NAME = "App.db"; | |
/*Category Contract*/ | |
public static final String CATEGORY_TABLE_NAME = "category"; | |
public static final String COLUMN_NAME_ID = "id"; | |
public static final String COLUMN_NAME_DESCRIPTION = "description"; | |
public static final String COLUMN_NAME_NAME = "name"; | |
public static final String COLUMN_NAME_COUNT = "count"; | |
public abstract CategoryDao getCategoryDao(); | |
public static AppDatabase getAppDatabase(Context context) { | |
if (INSTANCE == null) { | |
INSTANCE = | |
Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME) | |
// allow queries on the main thread. | |
// Don't do this on a real app! See PersistenceBasicSample for an example. | |
.allowMainThreadQueries() | |
.build(); | |
} | |
return INSTANCE; | |
} | |
public static void destroyInstance() { | |
INSTANCE = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment