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 "SEARCH_RECORD".
*/
public class SearchRecordDao extends AbstractDao<SearchRecord, Long> {

    public static final String TABLENAME = "SEARCH_RECORD";

    /**
     * Properties of entity SearchRecord.<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 Input = new Property(1, String.class, "input", false, "input");
        public final static Property First_time = new Property(2, long.class, "first_time", false, "first_time");
        public final static Property Last_time = new Property(3, long.class, "last_time", false, "last_time");
        public final static Property Count = new Property(4, int.class, "count", false, "count");
    }


    public SearchRecordDao(DaoConfig config) {
        super(config);
    }
    
    public SearchRecordDao(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 + "\"SEARCH_RECORD\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"input\" TEXT," + // 1: input
                "\"first_time\" INTEGER NOT NULL ," + // 2: first_time
                "\"last_time\" INTEGER NOT NULL ," + // 3: last_time
                "\"count\" INTEGER NOT NULL );"); // 4: count
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, SearchRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String input = entity.getInput();
        if (input != null) {
            stmt.bindString(2, input);
        }
        stmt.bindLong(3, entity.getFirst_time());
        stmt.bindLong(4, entity.getLast_time());
        stmt.bindLong(5, entity.getCount());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SearchRecord entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String input = entity.getInput();
        if (input != null) {
            stmt.bindString(2, input);
        }
        stmt.bindLong(3, entity.getFirst_time());
        stmt.bindLong(4, entity.getLast_time());
        stmt.bindLong(5, entity.getCount());
    }

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

    @Override
    public SearchRecord readEntity(Cursor cursor, int offset) {
        SearchRecord entity = new SearchRecord( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // input
            cursor.getLong(offset + 2), // first_time
            cursor.getLong(offset + 3), // last_time
            cursor.getInt(offset + 4) // count
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SearchRecord entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setInput(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setFirst_time(cursor.getLong(offset + 2));
        entity.setLast_time(cursor.getLong(offset + 3));
        entity.setCount(cursor.getInt(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SearchRecord entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SearchRecord entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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