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.systemConfig.domain.SystemConfigBean;

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

    public static final String TABLENAME = "DB_SYSTEM_CONFIG";

    /**
     * Properties of entity SystemConfigBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Code = new Property(0, String.class, "code", true, "CODE");
        public final static Property Desc = new Property(1, String.class, "desc", false, "DESC");
        public final static Property Value = new Property(2, String.class, "value", false, "VALUE");
    }


    public SystemConfigBeanDao(DaoConfig config) {
        super(config);
    }
    
    public SystemConfigBeanDao(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_SYSTEM_CONFIG\" (" + //
                "\"CODE\" TEXT PRIMARY KEY NOT NULL ," + // 0: code
                "\"DESC\" TEXT," + // 1: desc
                "\"VALUE\" TEXT);"); // 2: value
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, SystemConfigBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getCode());
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(2, desc);
        }
 
        String value = entity.getValue();
        if (value != null) {
            stmt.bindString(3, value);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SystemConfigBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getCode());
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(2, desc);
        }
 
        String value = entity.getValue();
        if (value != null) {
            stmt.bindString(3, value);
        }
    }

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

    @Override
    public SystemConfigBean readEntity(Cursor cursor, int offset) {
        SystemConfigBean entity = new SystemConfigBean( //
            cursor.getString(offset + 0), // code
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // desc
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // value
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SystemConfigBean entity, int offset) {
        entity.setCode(cursor.getString(offset + 0));
        entity.setDesc(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setValue(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final String updateKeyAfterInsert(SystemConfigBean entity, long rowId) {
        return entity.getCode();
    }
    
    @Override
    public String getKey(SystemConfigBean entity) {
        if(entity != null) {
            return entity.getCode();
        } else {
            return null;
        }
    }

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

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