package com.sheep.gamegroup.greendao.download;

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 "ACCEPT_TASK_RECORD".
*/
public class AcceptTaskRecordDao extends AbstractDao<AcceptTaskRecord, Long> {

    public static final String TABLENAME = "ACCEPT_TASK_RECORD";

    /**
     * Properties of entity AcceptTaskRecord.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property UserId = new Property(1, String.class, "userId", false, "user_id");
        public final static Property PackageName = new Property(2, String.class, "packageName", false, "package_name");
        public final static Property AcceptTime = new Property(3, long.class, "acceptTime", false, "accept_time");
        public final static Property RunTime = new Property(4, long.class, "runTime", false, "run_time");
    }


    public AcceptTaskRecordDao(DaoConfig config) {
        super(config);
    }
    
    public AcceptTaskRecordDao(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 + "\"ACCEPT_TASK_RECORD\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"user_id\" TEXT," + // 1: userId
                "\"package_name\" TEXT," + // 2: packageName
                "\"accept_time\" INTEGER NOT NULL ," + // 3: acceptTime
                "\"run_time\" INTEGER NOT NULL );"); // 4: runTime
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, AcceptTaskRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String userId = entity.getUserId();
        if (userId != null) {
            stmt.bindString(2, userId);
        }
 
        String packageName = entity.getPackageName();
        if (packageName != null) {
            stmt.bindString(3, packageName);
        }
        stmt.bindLong(4, entity.getAcceptTime());
        stmt.bindLong(5, entity.getRunTime());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AcceptTaskRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String userId = entity.getUserId();
        if (userId != null) {
            stmt.bindString(2, userId);
        }
 
        String packageName = entity.getPackageName();
        if (packageName != null) {
            stmt.bindString(3, packageName);
        }
        stmt.bindLong(4, entity.getAcceptTime());
        stmt.bindLong(5, entity.getRunTime());
    }

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

    @Override
    public AcceptTaskRecord readEntity(Cursor cursor, int offset) {
        AcceptTaskRecord entity = new AcceptTaskRecord( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // userId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // packageName
            cursor.getLong(offset + 3), // acceptTime
            cursor.getLong(offset + 4) // runTime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AcceptTaskRecord entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setUserId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setPackageName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setAcceptTime(cursor.getLong(offset + 3));
        entity.setRunTime(cursor.getLong(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AcceptTaskRecord entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AcceptTaskRecord entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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