package com.sunmi.sunmit2demo.bean;

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

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

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

    public static final String TABLENAME = "GV_BEANS";

    /**
     * Properties of entity GvBeans.<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 ImgId = new Property(1, int.class, "imgId", false, "IMG_ID");
        public final static Property ImgUrl = new Property(2, String.class, "imgUrl", false, "IMG_URL");
        public final static Property Name = new Property(3, String.class, "name", false, "NAME");
        public final static Property Price = new Property(4, String.class, "price", false, "PRICE");
        public final static Property Code = new Property(5, String.class, "code", false, "CODE");
        public final static Property Mode = new Property(6, int.class, "mode", false, "MODE");
        public final static Property Logo = new Property(7, int.class, "logo", false, "LOGO");
        public final static Property Number = new Property(8, int.class, "number", false, "NUMBER");
        public final static Property Unit = new Property(9, String.class, "unit", false, "UNIT");
    }


    public GvBeansDao(DaoConfig config) {
        super(config);
    }
    
    public GvBeansDao(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 + "\"GV_BEANS\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"IMG_ID\" INTEGER NOT NULL ," + // 1: imgId
                "\"IMG_URL\" TEXT," + // 2: imgUrl
                "\"NAME\" TEXT," + // 3: name
                "\"PRICE\" TEXT," + // 4: price
                "\"CODE\" TEXT," + // 5: code
                "\"MODE\" INTEGER NOT NULL ," + // 6: mode
                "\"LOGO\" INTEGER NOT NULL ," + // 7: logo
                "\"NUMBER\" INTEGER NOT NULL ," + // 8: number
                "\"UNIT\" TEXT);"); // 9: unit
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, GvBeans entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getImgId());
 
        String imgUrl = entity.getImgUrl();
        if (imgUrl != null) {
            stmt.bindString(3, imgUrl);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(5, price);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(6, code);
        }
        stmt.bindLong(7, entity.getMode());
        stmt.bindLong(8, entity.getLogo());
        stmt.bindLong(9, entity.getNumber());
 
        String unit = entity.getUnit();
        if (unit != null) {
            stmt.bindString(10, unit);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, GvBeans entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getImgId());
 
        String imgUrl = entity.getImgUrl();
        if (imgUrl != null) {
            stmt.bindString(3, imgUrl);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(5, price);
        }
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(6, code);
        }
        stmt.bindLong(7, entity.getMode());
        stmt.bindLong(8, entity.getLogo());
        stmt.bindLong(9, entity.getNumber());
 
        String unit = entity.getUnit();
        if (unit != null) {
            stmt.bindString(10, unit);
        }
    }

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

    @Override
    public GvBeans readEntity(Cursor cursor, int offset) {
        GvBeans entity = new GvBeans( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // imgId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // imgUrl
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // price
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // code
            cursor.getInt(offset + 6), // mode
            cursor.getInt(offset + 7), // logo
            cursor.getInt(offset + 8), // number
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // unit
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, GvBeans entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setImgId(cursor.getInt(offset + 1));
        entity.setImgUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPrice(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setCode(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setMode(cursor.getInt(offset + 6));
        entity.setLogo(cursor.getInt(offset + 7));
        entity.setNumber(cursor.getInt(offset + 8));
        entity.setUnit(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(GvBeans entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(GvBeans entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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