package com.hippo.ehviewer.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;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DOWNLOAD_DIRNAME".
*/
public class DownloadDirnameDao extends AbstractDao<DownloadDirname, Long> {

    public static final String TABLENAME = "DOWNLOAD_DIRNAME";

    /**
     * Properties of entity DownloadDirname.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Gid = new Property(0, long.class, "gid", true, "GID");
        public final static Property Dirname = new Property(1, String.class, "dirname", false, "DIRNAME");
    };


    public DownloadDirnameDao(DaoConfig config) {
        super(config);
    }
    
    public DownloadDirnameDao(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 + "\"DOWNLOAD_DIRNAME\" (" + //
                "\"GID\" INTEGER PRIMARY KEY NOT NULL ," + // 0: gid
                "\"DIRNAME\" TEXT);"); // 1: dirname
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, DownloadDirname entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getGid());
 
        String dirname = entity.getDirname();
        if (dirname != null) {
            stmt.bindString(2, dirname);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, DownloadDirname entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getGid());
 
        String dirname = entity.getDirname();
        if (dirname != null) {
            stmt.bindString(2, dirname);
        }
    }

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

    @Override
    public DownloadDirname readEntity(Cursor cursor, int offset) {
        DownloadDirname entity = new DownloadDirname( //
            cursor.getLong(offset + 0), // gid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1) // dirname
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, DownloadDirname entity, int offset) {
        entity.setGid(cursor.getLong(offset + 0));
        entity.setDirname(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(DownloadDirname entity, long rowId) {
        entity.setGid(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(DownloadDirname entity) {
        if(entity != null) {
            return entity.getGid();
        } else {
            return null;
        }
    }

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