package com.tofly.data.sql.dao;

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.tofly.ghrq_route.module.pipeAnalyze.domain.FieldsBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DB_MAP_FIELD_CONFIG".
*/
public class FieldsBeanDao extends AbstractDao<FieldsBean, String> {

    public static final String TABLENAME = "DB_MAP_FIELD_CONFIG";

    /**
     * Properties of entity FieldsBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property Key = new Property(1, String.class, "key", false, "KEY");
        public final static Property Value = new Property(2, String.class, "value", false, "VALUE");
        public final static Property Notes = new Property(3, String.class, "notes", false, "NOTES");
        public final static Property Sort = new Property(4, int.class, "sort", false, "SORT");
    }


    public FieldsBeanDao(DaoConfig config) {
        super(config);
    }
    
    public FieldsBeanDao(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 + "\"DB_MAP_FIELD_CONFIG\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"KEY\" TEXT," + // 1: key
                "\"VALUE\" TEXT," + // 2: value
                "\"NOTES\" TEXT," + // 3: notes
                "\"SORT\" INTEGER NOT NULL );"); // 4: sort
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, FieldsBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String key = entity.getKey();
        if (key != null) {
            stmt.bindString(2, key);
        }
 
        String value = entity.getValue();
        if (value != null) {
            stmt.bindString(3, value);
        }
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(4, notes);
        }
        stmt.bindLong(5, entity.getSort());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, FieldsBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String key = entity.getKey();
        if (key != null) {
            stmt.bindString(2, key);
        }
 
        String value = entity.getValue();
        if (value != null) {
            stmt.bindString(3, value);
        }
 
        String notes = entity.getNotes();
        if (notes != null) {
            stmt.bindString(4, notes);
        }
        stmt.bindLong(5, entity.getSort());
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.getString(offset + 0);
    }    

    @Override
    public FieldsBean readEntity(Cursor cursor, int offset) {
        FieldsBean entity = new FieldsBean( //
            cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // key
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // value
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // notes
            cursor.getInt(offset + 4) // sort
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, FieldsBean entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setKey(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setValue(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setNotes(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setSort(cursor.getInt(offset + 4));
     }
    
    @Override
    protected final String updateKeyAfterInsert(FieldsBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(FieldsBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(FieldsBean entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

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