GreenDaoUtils工具类

public class GreenDaoManage {
    private static GreenDaoManage instance;
    private DaoMaster.DevOpenHelper devOpenHelper;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;

    private GreenDaoManage(){

    }
    public static GreenDaoManage getInstance(){
        if (instance==null){
            synchronized (GreenDaoManage.class){
                if (instance==null){
                    instance = new GreenDaoManage();
                }
            }
        }
        return instance;
    }
    public void setDataBase(Context context){
        devOpenHelper = new DaoMaster.DevOpenHelper(context, "yang-db", null);
        db = devOpenHelper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    public SQLiteDatabase getDb() {
        return db;
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }
}

你可能感兴趣的:(GreenDaoUtils工具类)