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

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

    public static final String TABLENAME = "ORDERLINE";

    /**
     * Properties of entity OrderLine.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property OlCompo = new Property(0, String.class, "olCompo", true, "OL_COMPO");
        public final static Property OlOId = new Property(1, int.class, "olOId", false, "OL_O_ID");
        public final static Property OlDId = new Property(2, short.class, "olDId", false, "OL_D_ID");
        public final static Property OlWId = new Property(3, short.class, "olWId", false, "OL_W_ID");
        public final static Property OlNumber = new Property(4, short.class, "olNumber", false, "OL_NUMBER");
        public final static Property OlIId = new Property(5, int.class, "olIId", false, "OL_I_ID");
        public final static Property OlSupplyWId = new Property(6, short.class, "olSupplyWId", false, "OL_SUPPLY_WID");
        public final static Property OlDeliveryD = new Property(7, java.util.Date.class, "olDeliveryD", false, "OL_DELIVERY_D");
        public final static Property OlQuantity = new Property(8, short.class, "olQuantity", false, "OL_QUANTITY");
        public final static Property OlAmount = new Property(9, float.class, "olAmount", false, "OL_AMOUNT");
        public final static Property OlDistInfo = new Property(10, String.class, "olDistInfo", false, "OL_DIST_INFO");
        public final static Property OlDeliveryDInitial = new Property(11, java.util.Date.class, "olDeliveryDInitial", false, "OL_DELIVERY_DINITIAL");
        public final static Property OlInitial = new Property(12, Boolean.class, "olInitial", false, "OL_INITIAL");
    };


    public OrderLineDao(DaoConfig config) {
        super(config);
    }
    
    public OrderLineDao(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 + "\"ORDERLINE\" (" + //
                "\"OL_COMPO\" TEXT PRIMARY KEY NOT NULL ," + // 0: olCompo
                "\"OL_O_ID\" INTEGER NOT NULL ," + // 1: olOId
                "\"OL_D_ID\" INTEGER NOT NULL ," + // 2: olDId
                "\"OL_W_ID\" INTEGER NOT NULL ," + // 3: olWId
                "\"OL_NUMBER\" INTEGER NOT NULL ," + // 4: olNumber
                "\"OL_I_ID\" INTEGER NOT NULL ," + // 5: olIId
                "\"OL_SUPPLY_WID\" INTEGER NOT NULL ," + // 6: olSupplyWId
                "\"OL_DELIVERY_D\" INTEGER," + // 7: olDeliveryD
                "\"OL_QUANTITY\" INTEGER NOT NULL ," + // 8: olQuantity
                "\"OL_AMOUNT\" REAL NOT NULL ," + // 9: olAmount
                "\"OL_DIST_INFO\" TEXT NOT NULL ," + // 10: olDistInfo
                "\"OL_DELIVERY_DINITIAL\" INTEGER," + // 11: olDeliveryDInitial
                "\"OL_INITIAL\" INTEGER);"); // 12: olInitial
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, OrderLine entity) {
        stmt.clearBindings();
 
        String olCompo = entity.getOlCompo();
        if (olCompo != null) {
            stmt.bindString(1, olCompo);
        }
        stmt.bindLong(2, entity.getOlOId());
        stmt.bindLong(3, entity.getOlDId());
        stmt.bindLong(4, entity.getOlWId());
        stmt.bindLong(5, entity.getOlNumber());
        stmt.bindLong(6, entity.getOlIId());
        stmt.bindLong(7, entity.getOlSupplyWId());
 
        java.util.Date olDeliveryD = entity.getOlDeliveryD();
        if (olDeliveryD != null) {
            stmt.bindLong(8, olDeliveryD.getTime());
        }
        stmt.bindLong(9, entity.getOlQuantity());
        stmt.bindDouble(10, entity.getOlAmount());
        stmt.bindString(11, entity.getOlDistInfo());
 
        java.util.Date olDeliveryDInitial = entity.getOlDeliveryDInitial();
        if (olDeliveryDInitial != null) {
            stmt.bindLong(12, olDeliveryDInitial.getTime());
        }
 
        Boolean olInitial = entity.getOlInitial();
        if (olInitial != null) {
            stmt.bindLong(13, olInitial ? 1L: 0L);
        }
    }

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

    /** @inheritdoc */
    @Override
    public OrderLine readEntity(Cursor cursor, int offset) {
        OrderLine entity = new OrderLine( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // olCompo
            cursor.getInt(offset + 1), // olOId
            cursor.getShort(offset + 2), // olDId
            cursor.getShort(offset + 3), // olWId
            cursor.getShort(offset + 4), // olNumber
            cursor.getInt(offset + 5), // olIId
            cursor.getShort(offset + 6), // olSupplyWId
            cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)), // olDeliveryD
            cursor.getShort(offset + 8), // olQuantity
            cursor.getFloat(offset + 9), // olAmount
            cursor.getString(offset + 10), // olDistInfo
            cursor.isNull(offset + 11) ? null : new java.util.Date(cursor.getLong(offset + 11)), // olDeliveryDInitial
            cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0 // olInitial
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, OrderLine entity, int offset) {
        entity.setOlCompo(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setOlOId(cursor.getInt(offset + 1));
        entity.setOlDId(cursor.getShort(offset + 2));
        entity.setOlWId(cursor.getShort(offset + 3));
        entity.setOlNumber(cursor.getShort(offset + 4));
        entity.setOlIId(cursor.getInt(offset + 5));
        entity.setOlSupplyWId(cursor.getShort(offset + 6));
        entity.setOlDeliveryD(cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)));
        entity.setOlQuantity(cursor.getShort(offset + 8));
        entity.setOlAmount(cursor.getFloat(offset + 9));
        entity.setOlDistInfo(cursor.getString(offset + 10));
        entity.setOlDeliveryDInitial(cursor.isNull(offset + 11) ? null : new java.util.Date(cursor.getLong(offset + 11)));
        entity.setOlInitial(cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0);
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(OrderLine entity, long rowId) {
        return entity.getOlCompo();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(OrderLine entity) {
        if(entity != null) {
            return entity.getOlCompo();
        } else {
            return null;
        }
    }

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