package com.zhangke.shizhong.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "RATION_PLAN".
*/
public class RationPlanDao extends AbstractDao<RationPlan, Long> {

    public static final String TABLENAME = "RATION_PLAN";

    /**
     * Properties of entity RationPlan.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property StartDate = new Property(2, String.class, "startDate", false, "START_DATE");
        public final static Property FinishDate = new Property(3, String.class, "finishDate", false, "FINISH_DATE");
        public final static Property Current = new Property(4, double.class, "current", false, "CURRENT");
        public final static Property Target = new Property(5, double.class, "target", false, "TARGET");
        public final static Property Unit = new Property(6, String.class, "unit", false, "UNIT");
        public final static Property PlanType = new Property(7, int.class, "planType", false, "PLAN_TYPE");
        public final static Property PeriodIsOpen = new Property(8, boolean.class, "periodIsOpen", false, "PERIOD_IS_OPEN");
        public final static Property PeriodPlanType = new Property(9, int.class, "periodPlanType", false, "PERIOD_PLAN_TYPE");
        public final static Property PeriodPlanTarget = new Property(10, double.class, "periodPlanTarget", false, "PERIOD_PLAN_TARGET");
        public final static Property LastUpdatePeriodDate = new Property(11, String.class, "lastUpdatePeriodDate", false, "LAST_UPDATE_PERIOD_DATE");
    }

    private DaoSession daoSession;


    public RationPlanDao(DaoConfig config) {
        super(config);
    }
    
    public RationPlanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"RATION_PLAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"NAME\" TEXT," + // 1: name
                "\"START_DATE\" TEXT," + // 2: startDate
                "\"FINISH_DATE\" TEXT," + // 3: finishDate
                "\"CURRENT\" REAL NOT NULL ," + // 4: current
                "\"TARGET\" REAL NOT NULL ," + // 5: target
                "\"UNIT\" TEXT," + // 6: unit
                "\"PLAN_TYPE\" INTEGER NOT NULL ," + // 7: planType
                "\"PERIOD_IS_OPEN\" INTEGER NOT NULL ," + // 8: periodIsOpen
                "\"PERIOD_PLAN_TYPE\" INTEGER NOT NULL ," + // 9: periodPlanType
                "\"PERIOD_PLAN_TARGET\" REAL NOT NULL ," + // 10: periodPlanTarget
                "\"LAST_UPDATE_PERIOD_DATE\" TEXT);"); // 11: lastUpdatePeriodDate
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RATION_PLAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, RationPlan entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String startDate = entity.getStartDate();
        if (startDate != null) {
            stmt.bindString(3, startDate);
        }
 
        String finishDate = entity.getFinishDate();
        if (finishDate != null) {
            stmt.bindString(4, finishDate);
        }
        stmt.bindDouble(5, entity.getCurrent());
        stmt.bindDouble(6, entity.getTarget());
 
        String unit = entity.getUnit();
        if (unit != null) {
            stmt.bindString(7, unit);
        }
        stmt.bindLong(8, entity.getPlanType());
        stmt.bindLong(9, entity.getPeriodIsOpen() ? 1L: 0L);
        stmt.bindLong(10, entity.getPeriodPlanType());
        stmt.bindDouble(11, entity.getPeriodPlanTarget());
 
        String lastUpdatePeriodDate = entity.getLastUpdatePeriodDate();
        if (lastUpdatePeriodDate != null) {
            stmt.bindString(12, lastUpdatePeriodDate);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, RationPlan entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        String startDate = entity.getStartDate();
        if (startDate != null) {
            stmt.bindString(3, startDate);
        }
 
        String finishDate = entity.getFinishDate();
        if (finishDate != null) {
            stmt.bindString(4, finishDate);
        }
        stmt.bindDouble(5, entity.getCurrent());
        stmt.bindDouble(6, entity.getTarget());
 
        String unit = entity.getUnit();
        if (unit != null) {
            stmt.bindString(7, unit);
        }
        stmt.bindLong(8, entity.getPlanType());
        stmt.bindLong(9, entity.getPeriodIsOpen() ? 1L: 0L);
        stmt.bindLong(10, entity.getPeriodPlanType());
        stmt.bindDouble(11, entity.getPeriodPlanTarget());
 
        String lastUpdatePeriodDate = entity.getLastUpdatePeriodDate();
        if (lastUpdatePeriodDate != null) {
            stmt.bindString(12, lastUpdatePeriodDate);
        }
    }

    @Override
    protected final void attachEntity(RationPlan entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public RationPlan readEntity(Cursor cursor, int offset) {
        RationPlan entity = new RationPlan( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // startDate
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // finishDate
            cursor.getDouble(offset + 4), // current
            cursor.getDouble(offset + 5), // target
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // unit
            cursor.getInt(offset + 7), // planType
            cursor.getShort(offset + 8) != 0, // periodIsOpen
            cursor.getInt(offset + 9), // periodPlanType
            cursor.getDouble(offset + 10), // periodPlanTarget
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11) // lastUpdatePeriodDate
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, RationPlan entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setStartDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setFinishDate(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setCurrent(cursor.getDouble(offset + 4));
        entity.setTarget(cursor.getDouble(offset + 5));
        entity.setUnit(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setPlanType(cursor.getInt(offset + 7));
        entity.setPeriodIsOpen(cursor.getShort(offset + 8) != 0);
        entity.setPeriodPlanType(cursor.getInt(offset + 9));
        entity.setPeriodPlanTarget(cursor.getDouble(offset + 10));
        entity.setLastUpdatePeriodDate(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(RationPlan entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(RationPlan entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(RationPlan entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
