package io.innofang.base.bean.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;

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

    public static final String TABLENAME = "BPM";

    /**
     * Properties of entity Bpm.<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 MBpm = new Property(1, String.class, "mBpm", false, "M_BPM");
        public final static Property MTime = new Property(2, String.class, "mTime", false, "M_TIME");
        public final static Property MDescription = new Property(3, String.class, "mDescription", false, "M_DESCRIPTION");
    }


    public BpmDao(DaoConfig config) {
        super(config);
    }
    
    public BpmDao(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 + "\"BPM\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"M_BPM\" TEXT," + // 1: mBpm
                "\"M_TIME\" TEXT," + // 2: mTime
                "\"M_DESCRIPTION\" TEXT);"); // 3: mDescription
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, Bpm entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String mBpm = entity.getMBpm();
        if (mBpm != null) {
            stmt.bindString(2, mBpm);
        }
 
        String mTime = entity.getMTime();
        if (mTime != null) {
            stmt.bindString(3, mTime);
        }
 
        String mDescription = entity.getMDescription();
        if (mDescription != null) {
            stmt.bindString(4, mDescription);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Bpm entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String mBpm = entity.getMBpm();
        if (mBpm != null) {
            stmt.bindString(2, mBpm);
        }
 
        String mTime = entity.getMTime();
        if (mTime != null) {
            stmt.bindString(3, mTime);
        }
 
        String mDescription = entity.getMDescription();
        if (mDescription != null) {
            stmt.bindString(4, mDescription);
        }
    }

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

    @Override
    public Bpm readEntity(Cursor cursor, int offset) {
        Bpm entity = new Bpm( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // mBpm
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // mTime
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // mDescription
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Bpm entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setMBpm(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setMTime(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setMDescription(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Bpm entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Bpm entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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