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

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

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

import com.jingpu.android.apersistance.greendao.model.History;

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

    public static final String TABLENAME = "HISTORY";

    /**
     * Properties of entity History.<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 HCId = new Property(1, int.class, "hCId", false, "H_C_ID");
        public final static Property HCDId = new Property(2, short.class, "hCDId", false, "H_C_D_ID");
        public final static Property HCWId = new Property(3, short.class, "hCWId", false, "H_C_W_ID");
        public final static Property HDId = new Property(4, short.class, "hDId", false, "H_D_ID");
        public final static Property HWId = new Property(5, short.class, "hWId", false, "H_W_ID");
        public final static Property HDate = new Property(6, java.util.Date.class, "hDate", false, "H_DATE");
        public final static Property HAmount = new Property(7, float.class, "hAmount", false, "H_AMOUNT");
        public final static Property HData = new Property(8, String.class, "hData", false, "H_DATA");
        public final static Property HInitial = new Property(9, Boolean.class, "hInitial", false, "H_INITIAL");
    };


    public HistoryDao(DaoConfig config) {
        super(config);
    }
    
    public HistoryDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"HISTORY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"H_C_ID\" INTEGER NOT NULL ," + // 1: hCId
                "\"H_C_D_ID\" INTEGER NOT NULL ," + // 2: hCDId
                "\"H_C_W_ID\" INTEGER NOT NULL ," + // 3: hCWId
                "\"H_D_ID\" INTEGER NOT NULL ," + // 4: hDId
                "\"H_W_ID\" INTEGER NOT NULL ," + // 5: hWId
                "\"H_DATE\" INTEGER NOT NULL ," + // 6: hDate
                "\"H_AMOUNT\" REAL NOT NULL ," + // 7: hAmount
                "\"H_DATA\" TEXT NOT NULL ," + // 8: hData
                "\"H_INITIAL\" INTEGER);"); // 9: hInitial
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, History entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getHCId());
        stmt.bindLong(3, entity.getHCDId());
        stmt.bindLong(4, entity.getHCWId());
        stmt.bindLong(5, entity.getHDId());
        stmt.bindLong(6, entity.getHWId());
        stmt.bindLong(7, entity.getHDate().getTime());
        stmt.bindDouble(8, entity.getHAmount());
        stmt.bindString(9, entity.getHData());
 
        Boolean hInitial = entity.getHInitial();
        if (hInitial != null) {
            stmt.bindLong(10, hInitial ? 1L: 0L);
        }
    }

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

    /** @inheritdoc */
    @Override
    public History readEntity(Cursor cursor, int offset) {
        History entity = new History( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // hCId
            cursor.getShort(offset + 2), // hCDId
            cursor.getShort(offset + 3), // hCWId
            cursor.getShort(offset + 4), // hDId
            cursor.getShort(offset + 5), // hWId
            new java.util.Date(cursor.getLong(offset + 6)), // hDate
            cursor.getFloat(offset + 7), // hAmount
            cursor.getString(offset + 8), // hData
            cursor.isNull(offset + 9) ? null : cursor.getShort(offset + 9) != 0 // hInitial
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, History entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setHCId(cursor.getInt(offset + 1));
        entity.setHCDId(cursor.getShort(offset + 2));
        entity.setHCWId(cursor.getShort(offset + 3));
        entity.setHDId(cursor.getShort(offset + 4));
        entity.setHWId(cursor.getShort(offset + 5));
        entity.setHDate(new java.util.Date(cursor.getLong(offset + 6)));
        entity.setHAmount(cursor.getFloat(offset + 7));
        entity.setHData(cursor.getString(offset + 8));
        entity.setHInitial(cursor.isNull(offset + 9) ? null : cursor.getShort(offset + 9) != 0);
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(History entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(History entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
}
