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

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DISTRICT".
*/
public class DistrictDao extends AbstractDao<District, String> {

    public static final String TABLENAME = "DISTRICT";

    /**
     * Properties of entity District.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property DCompo = new Property(0, String.class, "dCompo", true, "D_COMPO");
        public final static Property DId = new Property(1, short.class, "dId", false, "D_ID");
        public final static Property DWId = new Property(2, short.class, "dWId", false, "D_W_ID");
        public final static Property DName = new Property(3, String.class, "dName", false, "D_NAME");
        public final static Property DStreet1 = new Property(4, String.class, "dStreet1", false, "D_STREET1");
        public final static Property DStreet2 = new Property(5, String.class, "dStreet2", false, "D_STREET2");
        public final static Property DCity = new Property(6, String.class, "dCity", false, "D_CITY");
        public final static Property DState = new Property(7, String.class, "dState", false, "D_STATE");
        public final static Property DZip = new Property(8, String.class, "dZip", false, "D_ZIP");
        public final static Property DTax = new Property(9, float.class, "dTax", false, "D_TAX");
        public final static Property DYtd = new Property(10, float.class, "dYtd", false, "D_YTD");
        public final static Property DNextOId = new Property(11, int.class, "dNextOId", false, "D_NEXT_OID");
    };


    public DistrictDao(DaoConfig config) {
        super(config);
    }
    
    public DistrictDao(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 + "\"DISTRICT\" (" + //
                "\"D_COMPO\" TEXT PRIMARY KEY NOT NULL ," + // 0: dCompo
                "\"D_ID\" INTEGER NOT NULL ," + // 1: dId
                "\"D_W_ID\" INTEGER NOT NULL ," + // 2: dWId
                "\"D_NAME\" TEXT NOT NULL ," + // 3: dName
                "\"D_STREET1\" TEXT NOT NULL ," + // 4: dStreet1
                "\"D_STREET2\" TEXT NOT NULL ," + // 5: dStreet2
                "\"D_CITY\" TEXT NOT NULL ," + // 6: dCity
                "\"D_STATE\" TEXT NOT NULL ," + // 7: dState
                "\"D_ZIP\" TEXT NOT NULL ," + // 8: dZip
                "\"D_TAX\" REAL NOT NULL ," + // 9: dTax
                "\"D_YTD\" REAL NOT NULL ," + // 10: dYtd
                "\"D_NEXT_OID\" INTEGER NOT NULL );"); // 11: dNextOId
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, District entity) {
        stmt.clearBindings();
 
        String dCompo = entity.getDCompo();
        if (dCompo != null) {
            stmt.bindString(1, dCompo);
        }
        stmt.bindLong(2, entity.getDId());
        stmt.bindLong(3, entity.getDWId());
        stmt.bindString(4, entity.getDName());
        stmt.bindString(5, entity.getDStreet1());
        stmt.bindString(6, entity.getDStreet2());
        stmt.bindString(7, entity.getDCity());
        stmt.bindString(8, entity.getDState());
        stmt.bindString(9, entity.getDZip());
        stmt.bindDouble(10, entity.getDTax());
        stmt.bindDouble(11, entity.getDYtd());
        stmt.bindLong(12, entity.getDNextOId());
    }

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

    /** @inheritdoc */
    @Override
    public District readEntity(Cursor cursor, int offset) {
        District entity = new District( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // dCompo
            cursor.getShort(offset + 1), // dId
            cursor.getShort(offset + 2), // dWId
            cursor.getString(offset + 3), // dName
            cursor.getString(offset + 4), // dStreet1
            cursor.getString(offset + 5), // dStreet2
            cursor.getString(offset + 6), // dCity
            cursor.getString(offset + 7), // dState
            cursor.getString(offset + 8), // dZip
            cursor.getFloat(offset + 9), // dTax
            cursor.getFloat(offset + 10), // dYtd
            cursor.getInt(offset + 11) // dNextOId
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, District entity, int offset) {
        entity.setDCompo(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setDId(cursor.getShort(offset + 1));
        entity.setDWId(cursor.getShort(offset + 2));
        entity.setDName(cursor.getString(offset + 3));
        entity.setDStreet1(cursor.getString(offset + 4));
        entity.setDStreet2(cursor.getString(offset + 5));
        entity.setDCity(cursor.getString(offset + 6));
        entity.setDState(cursor.getString(offset + 7));
        entity.setDZip(cursor.getString(offset + 8));
        entity.setDTax(cursor.getFloat(offset + 9));
        entity.setDYtd(cursor.getFloat(offset + 10));
        entity.setDNextOId(cursor.getInt(offset + 11));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(District entity, long rowId) {
        return entity.getDCompo();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(District entity) {
        if(entity != null) {
            return entity.getDCompo();
        } else {
            return null;
        }
    }

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