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

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

    public static final String TABLENAME = "DELIVERY_REQUEST";

    /**
     * Properties of entity DeliveryRequest.<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 DrWId = new Property(1, short.class, "drWId", false, "DR_W_ID");
        public final static Property DrCarrierId = new Property(2, short.class, "drCarrierId", false, "DR_CARRIER_ID");
        public final static Property DrQueued = new Property(3, java.util.Date.class, "drQueued", false, "DR_QUEUED");
        public final static Property DrCompleted = new Property(4, java.util.Date.class, "drCompleted", false, "DR_COMPLETED");
        public final static Property DrState = new Property(5, String.class, "drState", false, "DR_STATE");
    };


    public DeliveryRequestDao(DaoConfig config) {
        super(config);
    }
    
    public DeliveryRequestDao(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_REQUEST\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"DR_W_ID\" INTEGER NOT NULL ," + // 1: drWId
                "\"DR_CARRIER_ID\" INTEGER NOT NULL ," + // 2: drCarrierId
                "\"DR_QUEUED\" INTEGER NOT NULL ," + // 3: drQueued
                "\"DR_COMPLETED\" INTEGER," + // 4: drCompleted
                "\"DR_STATE\" TEXT);"); // 5: drState
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, DeliveryRequest entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getDrWId());
        stmt.bindLong(3, entity.getDrCarrierId());
        stmt.bindLong(4, entity.getDrQueued().getTime());
 
        java.util.Date drCompleted = entity.getDrCompleted();
        if (drCompleted != null) {
            stmt.bindLong(5, drCompleted.getTime());
        }
 
        String drState = entity.getDrState();
        if (drState != null) {
            stmt.bindString(6, drState);
        }
    }

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

    /** @inheritdoc */
    @Override
    public DeliveryRequest readEntity(Cursor cursor, int offset) {
        DeliveryRequest entity = new DeliveryRequest( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getShort(offset + 1), // drWId
            cursor.getShort(offset + 2), // drCarrierId
            new java.util.Date(cursor.getLong(offset + 3)), // drQueued
            cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // drCompleted
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // drState
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, DeliveryRequest entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDrWId(cursor.getShort(offset + 1));
        entity.setDrCarrierId(cursor.getShort(offset + 2));
        entity.setDrQueued(new java.util.Date(cursor.getLong(offset + 3)));
        entity.setDrCompleted(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
        entity.setDrState(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(DeliveryRequest entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(DeliveryRequest entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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