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.entity.CacheLabel;
import com.phlx.wool.entity.CacheLabelDao;
import com.phlx.wool.entity.DaoMaster;
import com.phlx.wool.entity.DivisionEntityDao;
import com.phlx.wool.entity.EntryRegistrationEntity;
import com.phlx.wool.entity.EntryRegistrationEntityDao;
import com.phlx.wool.entity.HarmlessDao;
import com.phlx.wool.entity.HarmlessDetailDao;
import com.phlx.wool.entity.LabelDao;
import com.phlx.wool.entity.MarkingDao;
import com.phlx.wool.entity.QuarantineDao;
import com.phlx.wool.entity.QuarantineDetailDao;
import com.phlx.wool.entity.TreatmentMethodDao;
import com.phlx.wool.entity.UnitDao;
import com.phlx.wool.entity.VarietyDao;
import com.phlx.wool.entity.VeterinaryDao;
import com.phlx.wool.entity.VillusBuyEntityDao;
import com.phlx.wool.entity.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);

    }

}
