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

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

    public static final String TABLENAME = "DELIVERY_ORDERS";

    /**
     * Properties of entity DeliveryOrders.<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 DoDrId = new Property(1, int.class, "doDrId", false, "DO_DR_ID");
        public final static Property DoDId = new Property(2, short.class, "doDId", false, "DO_D_ID");
        public final static Property DoOId = new Property(3, Integer.class, "doOId", false, "DO_O_ID");
    };


    public DeliveryOrdersDao(DaoConfig config) {
        super(config);
    }
    
    public DeliveryOrdersDao(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 + "\"DELIVERY_ORDERS\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"DO_DR_ID\" INTEGER NOT NULL ," + // 1: doDrId
                "\"DO_D_ID\" INTEGER NOT NULL ," + // 2: doDId
                "\"DO_O_ID\" INTEGER);"); // 3: doOId
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, DeliveryOrders entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getDoDrId());
        stmt.bindLong(3, entity.getDoDId());
 
        Integer doOId = entity.getDoOId();
        if (doOId != null) {
            stmt.bindLong(4, doOId);
        }
    }

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

    /** @inheritdoc */
    @Override
    public DeliveryOrders readEntity(Cursor cursor, int offset) {
        DeliveryOrders entity = new DeliveryOrders( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // doDrId
            cursor.getShort(offset + 2), // doDId
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3) // doOId
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, DeliveryOrders entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDoDrId(cursor.getInt(offset + 1));
        entity.setDoDId(cursor.getShort(offset + 2));
        entity.setDoOId(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(DeliveryOrders entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(DeliveryOrders entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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