package com.jingpu.android.apersistance.greendao.model;

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

import com.jingpu.android.apersistance.util.TPCCLog;

import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.identityscope.IdentityScopeType;

import com.jingpu.android.apersistance.greendao.model.CDao;
import com.jingpu.android.apersistance.greendao.model.WarehouseDao;
import com.jingpu.android.apersistance.greendao.model.DistrictDao;
import com.jingpu.android.apersistance.greendao.model.CustomerDao;
import com.jingpu.android.apersistance.greendao.model.HistoryDao;
import com.jingpu.android.apersistance.greendao.model.NewOrdersDao;
import com.jingpu.android.apersistance.greendao.model.OrdersDao;
import com.jingpu.android.apersistance.greendao.model.OrderLineDao;
import com.jingpu.android.apersistance.greendao.model.ItemDao;
import com.jingpu.android.apersistance.greendao.model.StockDao;
import com.jingpu.android.apersistance.greendao.model.DeliveryRequestDao;
import com.jingpu.android.apersistance.greendao.model.DeliveryOrdersDao;
import com.jingpu.android.apersistance.greendao.model.CategoryDao;
import com.jingpu.android.apersistance.greendao.model.CItemDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * Master of DAO (schema version 1): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 1;

    /** Creates underlying database table using DAOs. */
    public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
        CDao.createTable(db, ifNotExists);
        WarehouseDao.createTable(db, ifNotExists);
        DistrictDao.createTable(db, ifNotExists);
        CustomerDao.createTable(db, ifNotExists);
        HistoryDao.createTable(db, ifNotExists);
        NewOrdersDao.createTable(db, ifNotExists);
        OrdersDao.createTable(db, ifNotExists);
        OrderLineDao.createTable(db, ifNotExists);
        ItemDao.createTable(db, ifNotExists);
        StockDao.createTable(db, ifNotExists);
        DeliveryRequestDao.createTable(db, ifNotExists);
        DeliveryOrdersDao.createTable(db, ifNotExists);
        CategoryDao.createTable(db, ifNotExists);
        CItemDao.createTable(db, ifNotExists);
    }
    
    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
        CDao.dropTable(db, ifExists);
        WarehouseDao.dropTable(db, ifExists);
        DistrictDao.dropTable(db, ifExists);
        CustomerDao.dropTable(db, ifExists);
        HistoryDao.dropTable(db, ifExists);
        NewOrdersDao.dropTable(db, ifExists);
        OrdersDao.dropTable(db, ifExists);
        OrderLineDao.dropTable(db, ifExists);
        ItemDao.dropTable(db, ifExists);
        StockDao.dropTable(db, ifExists);
        DeliveryRequestDao.dropTable(db, ifExists);
        DeliveryOrdersDao.dropTable(db, ifExists);
        CategoryDao.dropTable(db, ifExists);
        CItemDao.dropTable(db, ifExists);
    }
    
    public static abstract class OpenHelper extends SQLiteOpenHelper {

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            TPCCLog.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }
    
    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            TPCCLog.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }

    public DaoMaster(SQLiteDatabase db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(CDao.class);
        registerDaoClass(WarehouseDao.class);
        registerDaoClass(DistrictDao.class);
        registerDaoClass(CustomerDao.class);
        registerDaoClass(HistoryDao.class);
        registerDaoClass(NewOrdersDao.class);
        registerDaoClass(OrdersDao.class);
        registerDaoClass(OrderLineDao.class);
        registerDaoClass(ItemDao.class);
        registerDaoClass(StockDao.class);
        registerDaoClass(DeliveryRequestDao.class);
        registerDaoClass(DeliveryOrdersDao.class);
        registerDaoClass(CategoryDao.class);
        registerDaoClass(CItemDao.class);
    }
    
    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }
    
    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }
    
}
