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.download.domain.DownloadData;

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

    public static final String TABLENAME = "DB_DOWNLOAD";

    /**
     * Properties of entity DownloadData.<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 Pid = new Property(1, String.class, "pid", false, "PID");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Cval = new Property(3, String.class, "cval", false, "CVAL");
        public final static Property CreateTime = new Property(4, String.class, "createTime", false, "CREATE_TIME");
        public final static Property Updatetime = new Property(5, String.class, "updatetime", false, "UPDATETIME");
        public final static Property CreateUser = new Property(6, String.class, "createUser", false, "CREATE_USER");
        public final static Property Ckey = new Property(7, String.class, "ckey", false, "CKEY");
        public final static Property Filetype = new Property(8, String.class, "filetype", false, "FILETYPE");
        public final static Property Datasize = new Property(9, String.class, "datasize", false, "DATASIZE");
        public final static Property Datatype = new Property(10, String.class, "datatype", false, "DATATYPE");
        public final static Property DownloadTime = new Property(11, String.class, "downloadTime", false, "DOWNLOAD_TIME");
        public final static Property Download_state = new Property(12, int.class, "download_state", false, "DOWNLOAD_STATE");
    }


    public DownloadDataDao(DaoConfig config) {
        super(config);
    }
    
    public DownloadDataDao(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_DOWNLOAD\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: id
                "\"PID\" TEXT," + // 1: pid
                "\"NAME\" TEXT," + // 2: name
                "\"CVAL\" TEXT," + // 3: cval
                "\"CREATE_TIME\" TEXT," + // 4: createTime
                "\"UPDATETIME\" TEXT," + // 5: updatetime
                "\"CREATE_USER\" TEXT," + // 6: createUser
                "\"CKEY\" TEXT," + // 7: ckey
                "\"FILETYPE\" TEXT," + // 8: filetype
                "\"DATASIZE\" TEXT," + // 9: datasize
                "\"DATATYPE\" TEXT," + // 10: datatype
                "\"DOWNLOAD_TIME\" TEXT," + // 11: downloadTime
                "\"DOWNLOAD_STATE\" INTEGER NOT NULL );"); // 12: download_state
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, DownloadData entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String pid = entity.getPid();
        if (pid != null) {
            stmt.bindString(2, pid);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String cval = entity.getCval();
        if (cval != null) {
            stmt.bindString(4, cval);
        }
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(5, createTime);
        }
 
        String updatetime = entity.getUpdatetime();
        if (updatetime != null) {
            stmt.bindString(6, updatetime);
        }
 
        String createUser = entity.getCreateUser();
        if (createUser != null) {
            stmt.bindString(7, createUser);
        }
 
        String ckey = entity.getCkey();
        if (ckey != null) {
            stmt.bindString(8, ckey);
        }
 
        String filetype = entity.getFiletype();
        if (filetype != null) {
            stmt.bindString(9, filetype);
        }
 
        String datasize = entity.getDatasize();
        if (datasize != null) {
            stmt.bindString(10, datasize);
        }
 
        String datatype = entity.getDatatype();
        if (datatype != null) {
            stmt.bindString(11, datatype);
        }
 
        String downloadTime = entity.getDownloadTime();
        if (downloadTime != null) {
            stmt.bindString(12, downloadTime);
        }
        stmt.bindLong(13, entity.getDownload_state());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, DownloadData entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String pid = entity.getPid();
        if (pid != null) {
            stmt.bindString(2, pid);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String cval = entity.getCval();
        if (cval != null) {
            stmt.bindString(4, cval);
        }
 
        String createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindString(5, createTime);
        }
 
        String updatetime = entity.getUpdatetime();
        if (updatetime != null) {
            stmt.bindString(6, updatetime);
        }
 
        String createUser = entity.getCreateUser();
        if (createUser != null) {
            stmt.bindString(7, createUser);
        }
 
        String ckey = entity.getCkey();
        if (ckey != null) {
            stmt.bindString(8, ckey);
        }
 
        String filetype = entity.getFiletype();
        if (filetype != null) {
            stmt.bindString(9, filetype);
        }
 
        String datasize = entity.getDatasize();
        if (datasize != null) {
            stmt.bindString(10, datasize);
        }
 
        String datatype = entity.getDatatype();
        if (datatype != null) {
            stmt.bindString(11, datatype);
        }
 
        String downloadTime = entity.getDownloadTime();
        if (downloadTime != null) {
            stmt.bindString(12, downloadTime);
        }
        stmt.bindLong(13, entity.getDownload_state());
    }

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

    @Override
    public DownloadData readEntity(Cursor cursor, int offset) {
        DownloadData entity = new DownloadData( //
            cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // pid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // cval
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // createTime
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // updatetime
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // createUser
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // ckey
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // filetype
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // datasize
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // datatype
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // downloadTime
            cursor.getInt(offset + 12) // download_state
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, DownloadData entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setPid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setCval(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setCreateTime(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setUpdatetime(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setCreateUser(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setCkey(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setFiletype(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setDatasize(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setDatatype(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setDownloadTime(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setDownload_state(cursor.getInt(offset + 12));
     }
    
    @Override
    protected final String updateKeyAfterInsert(DownloadData entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(DownloadData entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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