package com.phlx.wool.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.github.yuweiguocn.library.greendao.MigrationHelper;
import com.phlx.wool.db.gen.CacheLabelDao;
import com.phlx.wool.db.gen.DaoMaster;
import com.phlx.wool.db.gen.DivisionEntityDao;
import com.phlx.wool.db.gen.EntryRegistrationEntityDao;
import com.phlx.wool.db.gen.HarmlessDao;
import com.phlx.wool.db.gen.HarmlessDetailDao;
import com.phlx.wool.db.gen.LabelDao;
import com.phlx.wool.db.gen.MarkingDao;
import com.phlx.wool.db.gen.QuarantineDao;
import com.phlx.wool.db.gen.QuarantineDetailDao;
import com.phlx.wool.db.gen.TreatmentMethodDao;
import com.phlx.wool.db.gen.UnitDao;
import com.phlx.wool.db.gen.VarietyDao;
import com.phlx.wool.db.gen.VeterinaryDao;
import com.phlx.wool.db.gen.VillusBuyEntityDao;
import com.phlx.wool.db.gen.VillusGaugeEntityDao;

import org.greenrobot.greendao.database.Database;

public class MyOpenHelper extends DaoMaster.DevOpenHelper {

    public MyOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
        super(context, name, factory);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        //把需要管理的数据库表DAO作为最后一个参数传入到方法中
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {
            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }
            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        },  DivisionEntityDao.class,  HarmlessDao.class,  HarmlessDetailDao.class,  LabelDao.class
                ,  MarkingDao.class,  QuarantineDao.class,  QuarantineDetailDao.class
                ,  TreatmentMethodDao.class,  UnitDao.class,  VarietyDao.class,  VeterinaryDao.class
                ,  VillusBuyEntityDao.class,  VillusGaugeEntityDao.class, EntryRegistrationEntityDao.class, CacheLabelDao.class);

    }

}
