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.Warehouse;

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

    public static final String TABLENAME = "WAREHOUSE";

    /**
     * Properties of entity Warehouse.<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 WName = new Property(1, String.class, "wName", false, "W_NAME");
        public final static Property WStreet1 = new Property(2, String.class, "wStreet1", false, "W_STREET1");
        public final static Property WStreet2 = new Property(3, String.class, "wStreet2", false, "W_STREET2");
        public final static Property WCity = new Property(4, String.class, "wCity", false, "W_CITY");
        public final static Property WState = new Property(5, String.class, "wState", false, "W_STATE");
        public final static Property WZip = new Property(6, String.class, "wZip", false, "W_ZIP");
        public final static Property WTax = new Property(7, float.class, "wTax", false, "W_TAX");
        public final static Property WYtd = new Property(8, float.class, "wYtd", false, "W_YTD");
    };


    public WarehouseDao(DaoConfig config) {
        super(config);
    }
    
    public WarehouseDao(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 + "\"WAREHOUSE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"W_NAME\" TEXT NOT NULL ," + // 1: wName
                "\"W_STREET1\" TEXT NOT NULL ," + // 2: wStreet1
                "\"W_STREET2\" TEXT NOT NULL ," + // 3: wStreet2
                "\"W_CITY\" TEXT NOT NULL ," + // 4: wCity
                "\"W_STATE\" TEXT NOT NULL ," + // 5: wState
                "\"W_ZIP\" TEXT NOT NULL ," + // 6: wZip
                "\"W_TAX\" REAL NOT NULL ," + // 7: wTax
                "\"W_YTD\" REAL NOT NULL );"); // 8: wYtd
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Warehouse entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindString(2, entity.getWName());
        stmt.bindString(3, entity.getWStreet1());
        stmt.bindString(4, entity.getWStreet2());
        stmt.bindString(5, entity.getWCity());
        stmt.bindString(6, entity.getWState());
        stmt.bindString(7, entity.getWZip());
        stmt.bindDouble(8, entity.getWTax());
        stmt.bindDouble(9, entity.getWYtd());
    }

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

    /** @inheritdoc */
    @Override
    public Warehouse readEntity(Cursor cursor, int offset) {
        Warehouse entity = new Warehouse( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getString(offset + 1), // wName
            cursor.getString(offset + 2), // wStreet1
            cursor.getString(offset + 3), // wStreet2
            cursor.getString(offset + 4), // wCity
            cursor.getString(offset + 5), // wState
            cursor.getString(offset + 6), // wZip
            cursor.getFloat(offset + 7), // wTax
            cursor.getFloat(offset + 8) // wYtd
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Warehouse entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setWName(cursor.getString(offset + 1));
        entity.setWStreet1(cursor.getString(offset + 2));
        entity.setWStreet2(cursor.getString(offset + 3));
        entity.setWCity(cursor.getString(offset + 4));
        entity.setWState(cursor.getString(offset + 5));
        entity.setWZip(cursor.getString(offset + 6));
        entity.setWTax(cursor.getFloat(offset + 7));
        entity.setWYtd(cursor.getFloat(offset + 8));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Warehouse entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Warehouse entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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