org.greenrobot.greendao.database.DatabaseOpenHelper Java Examples

The following examples show how to use org.greenrobot.greendao.database.DatabaseOpenHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBRepository.java    From FriendBook with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 初始化greenDao,这个操作建议在Application初始化的时候添加;
 */
public static void initDatabase(Context context) {
    if (mDaoSession != null) {
        return;
    }
    if (context == null) {
        throw new IllegalArgumentException("You cannot start a load on a null Context");
    }
    DatabaseOpenHelper mHelper;
    mHelper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), DB_NAME);
   /* if (BuildConfig.DEBUG) {
        mHelper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), DB_NAME);
    } else {
        mHelper = new MySQLiteOpenHelper(context.getApplicationContext(), DB_NAME);
    }*/
    Database db = mHelper.getWritableDb();
    DaoMaster mDaoMaster = new DaoMaster(db);
    mDaoSession = mDaoMaster.newSession();
}