package com.oo.eye.gen;

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.oo.eye.bean.EyeChartsBean;

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

    public static final String TABLENAME = "EYE_CHARTS_BEAN";

    /**
     * Properties of entity EyeChartsBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Charts_id = new Property(0, Long.class, "charts_id", true, "_id");
        public final static Property Left_eye = new Property(1, double.class, "left_eye", false, "LEFT_EYE");
        public final static Property Right_eye = new Property(2, double.class, "right_eye", false, "RIGHT_EYE");
        public final static Property Type = new Property(3, int.class, "type", false, "TYPE");
        public final static Property Created_month = new Property(4, String.class, "created_month", false, "CREATED_MONTH");
    }


    public EyeChartsBeanDao(DaoConfig config) {
        super(config);
    }
    
    public EyeChartsBeanDao(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 + "\"EYE_CHARTS_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: charts_id
                "\"LEFT_EYE\" REAL NOT NULL ," + // 1: left_eye
                "\"RIGHT_EYE\" REAL NOT NULL ," + // 2: right_eye
                "\"TYPE\" INTEGER NOT NULL ," + // 3: type
                "\"CREATED_MONTH\" TEXT NOT NULL UNIQUE );"); // 4: created_month
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, EyeChartsBean entity) {
        stmt.clearBindings();
 
        Long charts_id = entity.getCharts_id();
        if (charts_id != null) {
            stmt.bindLong(1, charts_id);
        }
        stmt.bindDouble(2, entity.getLeft_eye());
        stmt.bindDouble(3, entity.getRight_eye());
        stmt.bindLong(4, entity.getType());
        stmt.bindString(5, entity.getCreated_month());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, EyeChartsBean entity) {
        stmt.clearBindings();
 
        Long charts_id = entity.getCharts_id();
        if (charts_id != null) {
            stmt.bindLong(1, charts_id);
        }
        stmt.bindDouble(2, entity.getLeft_eye());
        stmt.bindDouble(3, entity.getRight_eye());
        stmt.bindLong(4, entity.getType());
        stmt.bindString(5, entity.getCreated_month());
    }

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

    @Override
    public EyeChartsBean readEntity(Cursor cursor, int offset) {
        EyeChartsBean entity = new EyeChartsBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // charts_id
            cursor.getDouble(offset + 1), // left_eye
            cursor.getDouble(offset + 2), // right_eye
            cursor.getInt(offset + 3), // type
            cursor.getString(offset + 4) // created_month
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, EyeChartsBean entity, int offset) {
        entity.setCharts_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setLeft_eye(cursor.getDouble(offset + 1));
        entity.setRight_eye(cursor.getDouble(offset + 2));
        entity.setType(cursor.getInt(offset + 3));
        entity.setCreated_month(cursor.getString(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(EyeChartsBean entity, long rowId) {
        entity.setCharts_id(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(EyeChartsBean entity) {
        if(entity != null) {
            return entity.getCharts_id();
        } else {
            return null;
        }
    }

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

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