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

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

    public static final String TABLENAME = "ORDERS";

    /**
     * Properties of entity Orders.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property OCompo = new Property(0, String.class, "oCompo", true, "O_COMPO");
        public final static Property OId = new Property(1, int.class, "oId", false, "O_ID");
        public final static Property ODId = new Property(2, short.class, "oDId", false, "O_D_ID");
        public final static Property OWId = new Property(3, short.class, "oWId", false, "O_W_ID");
        public final static Property OCId = new Property(4, int.class, "oCId", false, "O_C_ID");
        public final static Property OEntryD = new Property(5, String.class, "oEntryD", false, "O_ENTRY_D");
        public final static Property OCarrierId = new Property(6, Short.class, "oCarrierId", false, "O_CARRIER_ID");
        public final static Property OOlCnt = new Property(7, short.class, "oOlCnt", false, "O_OL_CNT");
        public final static Property OAllLocal = new Property(8, short.class, "oAllLocal", false, "O_ALL_LOCAL");
        public final static Property OCarrierIdInitial = new Property(9, Short.class, "oCarrierIdInitial", false, "O_CARRIER_ID_INITIAL");
        public final static Property OInitial = new Property(10, Boolean.class, "oInitial", false, "O_INITIAL");
    };


    public OrdersDao(DaoConfig config) {
        super(config);
    }
    
    public OrdersDao(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 + "\"ORDERS\" (" + //
                "\"O_COMPO\" TEXT PRIMARY KEY NOT NULL ," + // 0: oCompo
                "\"O_ID\" INTEGER NOT NULL ," + // 1: oId
                "\"O_D_ID\" INTEGER NOT NULL ," + // 2: oDId
                "\"O_W_ID\" INTEGER NOT NULL ," + // 3: oWId
                "\"O_C_ID\" INTEGER NOT NULL ," + // 4: oCId
                "\"O_ENTRY_D\" TEXT NOT NULL ," + // 5: oEntryD
                "\"O_CARRIER_ID\" INTEGER," + // 6: oCarrierId
                "\"O_OL_CNT\" INTEGER NOT NULL ," + // 7: oOlCnt
                "\"O_ALL_LOCAL\" INTEGER NOT NULL ," + // 8: oAllLocal
                "\"O_CARRIER_ID_INITIAL\" INTEGER," + // 9: oCarrierIdInitial
                "\"O_INITIAL\" INTEGER);"); // 10: oInitial
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Orders entity) {
        stmt.clearBindings();
 
        String oCompo = entity.getOCompo();
        if (oCompo != null) {
            stmt.bindString(1, oCompo);
        }
        stmt.bindLong(2, entity.getOId());
        stmt.bindLong(3, entity.getODId());
        stmt.bindLong(4, entity.getOWId());
        stmt.bindLong(5, entity.getOCId());
        stmt.bindString(6, entity.getOEntryD());
 
        Short oCarrierId = entity.getOCarrierId();
        if (oCarrierId != null) {
            stmt.bindLong(7, oCarrierId);
        }
        stmt.bindLong(8, entity.getOOlCnt());
        stmt.bindLong(9, entity.getOAllLocal());
 
        Short oCarrierIdInitial = entity.getOCarrierIdInitial();
        if (oCarrierIdInitial != null) {
            stmt.bindLong(10, oCarrierIdInitial);
        }
 
        Boolean oInitial = entity.getOInitial();
        if (oInitial != null) {
            stmt.bindLong(11, oInitial ? 1L: 0L);
        }
    }

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

    /** @inheritdoc */
    @Override
    public Orders readEntity(Cursor cursor, int offset) {
        Orders entity = new Orders( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // oCompo
            cursor.getInt(offset + 1), // oId
            cursor.getShort(offset + 2), // oDId
            cursor.getShort(offset + 3), // oWId
            cursor.getInt(offset + 4), // oCId
            cursor.getString(offset + 5), // oEntryD
            cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6), // oCarrierId
            cursor.getShort(offset + 7), // oOlCnt
            cursor.getShort(offset + 8), // oAllLocal
            cursor.isNull(offset + 9) ? null : cursor.getShort(offset + 9), // oCarrierIdInitial
            cursor.isNull(offset + 10) ? null : cursor.getShort(offset + 10) != 0 // oInitial
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Orders entity, int offset) {
        entity.setOCompo(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setOId(cursor.getInt(offset + 1));
        entity.setODId(cursor.getShort(offset + 2));
        entity.setOWId(cursor.getShort(offset + 3));
        entity.setOCId(cursor.getInt(offset + 4));
        entity.setOEntryD(cursor.getString(offset + 5));
        entity.setOCarrierId(cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6));
        entity.setOOlCnt(cursor.getShort(offset + 7));
        entity.setOAllLocal(cursor.getShort(offset + 8));
        entity.setOCarrierIdInitial(cursor.isNull(offset + 9) ? null : cursor.getShort(offset + 9));
        entity.setOInitial(cursor.isNull(offset + 10) ? null : cursor.getShort(offset + 10) != 0);
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Orders entity, long rowId) {
        return entity.getOCompo();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Orders entity) {
        if(entity != null) {
            return entity.getOCompo();
        } else {
            return null;
        }
    }

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