package com.gingersoft.gsa.cloud.database.greendao;

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;

import com.gingersoft.gsa.cloud.database.bean.Combo;

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

    public static final String TABLENAME = "COMBO";

    /**
     * Properties of entity Combo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Dbid = new Property(0, Long.class, "dbid", true, "_id");
        public final static Property Id = new Property(1, Long.class, "id", false, "ID");
        public final static Property Fid = new Property(2, Long.class, "fid", false, "FID");
        public final static Property ComId = new Property(3, int.class, "comId", false, "COM_ID");
    }

    private DaoSession daoSession;


    public ComboDao(DaoConfig config) {
        super(config);
    }
    
    public ComboDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"COMBO\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: dbid
                "\"ID\" INTEGER NOT NULL ," + // 1: id
                "\"FID\" INTEGER," + // 2: fid
                "\"COM_ID\" INTEGER NOT NULL );"); // 3: comId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, Combo entity) {
        stmt.clearBindings();
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(1, dbid);
        }
        stmt.bindLong(2, entity.getId());
 
        Long fid = entity.getFid();
        if (fid != null) {
            stmt.bindLong(3, fid);
        }
        stmt.bindLong(4, entity.getComId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Combo entity) {
        stmt.clearBindings();
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(1, dbid);
        }
        stmt.bindLong(2, entity.getId());
 
        Long fid = entity.getFid();
        if (fid != null) {
            stmt.bindLong(3, fid);
        }
        stmt.bindLong(4, entity.getComId());
    }

    @Override
    protected final void attachEntity(Combo entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public Combo readEntity(Cursor cursor, int offset) {
        Combo entity = new Combo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // dbid
            cursor.getLong(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // fid
            cursor.getInt(offset + 3) // comId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Combo entity, int offset) {
        entity.setDbid(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.getLong(offset + 1));
        entity.setFid(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2));
        entity.setComId(cursor.getInt(offset + 3));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Combo entity, long rowId) {
        entity.setDbid(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Combo entity) {
        if(entity != null) {
            return entity.getDbid();
        } else {
            return null;
        }
    }

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

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