package com.kfzs.duanduan.data.graph.provider.channel;

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 "CHANNEL".
*/
public class ChannelDao extends AbstractDao<Channel, Long> {

    public static final String TABLENAME = "CHANNEL";

    /**
     * Properties of entity Channel.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property MId = new Property(0, Long.class, "mId", true, "_id");
        public final static Property MChannelName = new Property(1, String.class, "mChannelName", false, "channel_name");
        public final static Property MChannelNum = new Property(2, String.class, "mChannelNum", false, "channel_num");
    }


    public ChannelDao(DaoConfig config) {
        super(config);
    }
    
    public ChannelDao(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 + "\"CHANNEL\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: mId
                "\"channel_name\" TEXT," + // 1: mChannelName
                "\"channel_num\" TEXT);"); // 2: mChannelNum
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, Channel entity) {
        stmt.clearBindings();
 
        Long mId = entity.getMId();
        if (mId != null) {
            stmt.bindLong(1, mId);
        }
 
        String mChannelName = entity.getMChannelName();
        if (mChannelName != null) {
            stmt.bindString(2, mChannelName);
        }
 
        String mChannelNum = entity.getMChannelNum();
        if (mChannelNum != null) {
            stmt.bindString(3, mChannelNum);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Channel entity) {
        stmt.clearBindings();
 
        Long mId = entity.getMId();
        if (mId != null) {
            stmt.bindLong(1, mId);
        }
 
        String mChannelName = entity.getMChannelName();
        if (mChannelName != null) {
            stmt.bindString(2, mChannelName);
        }
 
        String mChannelNum = entity.getMChannelNum();
        if (mChannelNum != null) {
            stmt.bindString(3, mChannelNum);
        }
    }

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

    @Override
    public Channel readEntity(Cursor cursor, int offset) {
        Channel entity = new Channel( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // mId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // mChannelName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // mChannelNum
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Channel entity, int offset) {
        entity.setMId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setMChannelName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setMChannelNum(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Channel entity, long rowId) {
        entity.setMId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Channel entity) {
        if(entity != null) {
            return entity.getMId();
        } else {
            return null;
        }
    }

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

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