Search in sources :

Example 1 with MyOpenHelper

use of com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper in project GzuClassSchedule by mnnyang.

the class Cache method initGreenDao.

private void initGreenDao(Context context) {
    MyOpenHelper devOpenHelper = new MyOpenHelper(context, "coursev2.db", null);
    DaoMaster daoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
    DaoSession daoSession = daoMaster.newSession();
    mCourseGroupDao = daoSession.getCourseGroupDao();
    mCourseV2Dao = daoSession.getCourseV2Dao();
}
Also used : MyOpenHelper(com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper) DaoMaster(com.mnnyang.gzuclassschedule.data.greendao.DaoMaster) DaoSession(com.mnnyang.gzuclassschedule.data.greendao.DaoSession)

Example 2 with MyOpenHelper

use of com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper in project GzuClassSchedule by mnnyang.

the class AppUtils method migrateData.

/**
 * 迁移旧数据
 */
private static void migrateData(Context context) {
    MyOpenHelper myOpenHelper = new MyOpenHelper(context, "coursev2.db", null);
    DaoMaster daoMaster = new DaoMaster(myOpenHelper.getWritableDatabase());
    DaoSession daoSession = daoMaster.newSession();
    CourseGroupDao courseGroupDao = daoSession.getCourseGroupDao();
    CourseV2Dao courseV2Dao = daoSession.getCourseV2Dao();
    ArrayList<CsItem> csItems = CourseDbDao.instance().loadCsNameList();
    for (CsItem csItem : csItems) {
        ArrayList<Course> courses = CourseDbDao.instance().loadCourses(csItem.getCsName().getCsNameId());
        CourseGroup group = new CourseGroup();
        group.setCgName(csItem.getCsName().getName());
        long insert1 = courseGroupDao.insert(group);
        for (Course course : courses) {
            if (course.getNodes() == null || course.getNodes().size() == 0 || course.getEndWeek() == 0) {
                continue;
            }
            CourseV2 courseV2 = new CourseV2().setCouOnlyId(AppUtils.createUUID());
            courseV2.setCouName(course.getName());
            courseV2.setCouTeacher(course.getTeacher());
            courseV2.setCouLocation(course.getClassRoom());
            // node
            courseV2.setCouStartNode(course.getNodes().get(0));
            courseV2.setCouNodeCount(course.getNodes().size());
            // day
            courseV2.setCouWeek(course.getWeek());
            // week
            String couAllWeek = getAllWeek(course);
            if (couAllWeek.length() > 0) {
                couAllWeek = couAllWeek.substring(0, couAllWeek.length() - 1);
            }
            courseV2.setCouAllWeek(couAllWeek);
            courseV2.setCouCgId(insert1);
            courseV2Dao.insert(courseV2);
        }
    }
}
Also used : MyOpenHelper(com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper) CourseV2Dao(com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao) CourseGroupDao(com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao) CourseGroup(com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup) CsItem(com.mnnyang.gzuclassschedule.data.bean.CsItem) DaoMaster(com.mnnyang.gzuclassschedule.data.greendao.DaoMaster) CourseV2(com.mnnyang.gzuclassschedule.data.beanv2.CourseV2) Course(com.mnnyang.gzuclassschedule.data.bean.Course) DaoSession(com.mnnyang.gzuclassschedule.data.greendao.DaoSession)

Aggregations

DaoMaster (com.mnnyang.gzuclassschedule.data.greendao.DaoMaster)2 DaoSession (com.mnnyang.gzuclassschedule.data.greendao.DaoSession)2 MyOpenHelper (com.mnnyang.gzuclassschedule.data.greendao.MyOpenHelper)2 Course (com.mnnyang.gzuclassschedule.data.bean.Course)1 CsItem (com.mnnyang.gzuclassschedule.data.bean.CsItem)1 CourseGroup (com.mnnyang.gzuclassschedule.data.beanv2.CourseGroup)1 CourseV2 (com.mnnyang.gzuclassschedule.data.beanv2.CourseV2)1 CourseGroupDao (com.mnnyang.gzuclassschedule.data.greendao.CourseGroupDao)1 CourseV2Dao (com.mnnyang.gzuclassschedule.data.greendao.CourseV2Dao)1