package com.sunzee.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import com.sunzee.model.domain.LocalOrderBean;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.internal.DaoConfig;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * DAO for table "LOCAL_ORDER_BEAN".
*/
public class LocalOrderBeanDao extends AbstractDao<LocalOrderBean, Long> {

    public static final String TABLENAME = "LOCAL_ORDER_BEAN";

    /**
     * Properties of entity LocalOrderBean.<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 Name = new Property(1, String.class, "name", false, "name");
        public final static Property Price = new Property(2, double.class, "price", false, "price");
        public final static Property PayType = new Property(3, int.class, "payType", false, "paytype");
        public final static Property Sn = new Property(4, String.class, "sn", false, "sn");
        public final static Property Time = new Property(5, String.class, "time", false, "time");
    }


    public LocalOrderBeanDao(DaoConfig config) {
        super(config);
    }
    
    public LocalOrderBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"LOCAL_ORDER_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"name\" TEXT," + // 1: name
                "\"price\" REAL NOT NULL ," + // 2: price
                "\"paytype\" INTEGER NOT NULL ," + // 3: payType
                "\"sn\" TEXT," + // 4: sn
                "\"time\" TEXT);"); // 5: time
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, LocalOrderBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
        stmt.bindDouble(3, entity.getPrice());
        stmt.bindLong(4, entity.getPayType());
 
        String sn = entity.getSn();
        if (sn != null) {
            stmt.bindString(5, sn);
        }
 
        String time = entity.getTime();
        if (time != null) {
            stmt.bindString(6, time);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, LocalOrderBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
        stmt.bindDouble(3, entity.getPrice());
        stmt.bindLong(4, entity.getPayType());
 
        String sn = entity.getSn();
        if (sn != null) {
            stmt.bindString(5, sn);
        }
 
        String time = entity.getTime();
        if (time != null) {
            stmt.bindString(6, time);
        }
    }

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

    @Override
    public LocalOrderBean readEntity(Cursor cursor, int offset) {
        LocalOrderBean entity = new LocalOrderBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.getDouble(offset + 2), // price
            cursor.getInt(offset + 3), // payType
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // sn
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // time
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, LocalOrderBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPrice(cursor.getDouble(offset + 2));
        entity.setPayType(cursor.getInt(offset + 3));
        entity.setSn(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setTime(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(LocalOrderBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(LocalOrderBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(LocalOrderBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
