package me.anany.weikandian.db;

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 me.anany.weikandian.entry.HomeTitle;

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

    public static final String TABLENAME = "HOME_TITLE";

    /**
     * Properties of entity HomeTitle.<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 Id = new Property(1, String.class, "id", false, "ID");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Sname = new Property(3, String.class, "sname", false, "SNAME");
        public final static Property Pic = new Property(4, String.class, "pic", false, "PIC");
        public final static Property Bookcount = new Property(5, String.class, "bookcount", false, "BOOKCOUNT");
        public final static Property Description = new Property(6, String.class, "description", false, "DESCRIPTION");
        public final static Property Realcount = new Property(7, String.class, "realcount", false, "REALCOUNT");
    }


    public HomeTitleDao(DaoConfig config) {
        super(config);
    }
    
    public HomeTitleDao(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 + "\"HOME_TITLE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _id
                "\"ID\" TEXT," + // 1: id
                "\"NAME\" TEXT," + // 2: name
                "\"SNAME\" TEXT," + // 3: sname
                "\"PIC\" TEXT," + // 4: pic
                "\"BOOKCOUNT\" TEXT," + // 5: bookcount
                "\"DESCRIPTION\" TEXT," + // 6: description
                "\"REALCOUNT\" TEXT);"); // 7: realcount
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, HomeTitle entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String sname = entity.getSname();
        if (sname != null) {
            stmt.bindString(4, sname);
        }
 
        String pic = entity.getPic();
        if (pic != null) {
            stmt.bindString(5, pic);
        }
 
        String bookcount = entity.getBookcount();
        if (bookcount != null) {
            stmt.bindString(6, bookcount);
        }
 
        String description = entity.getDescription();
        if (description != null) {
            stmt.bindString(7, description);
        }
 
        String realcount = entity.getRealcount();
        if (realcount != null) {
            stmt.bindString(8, realcount);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, HomeTitle entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String sname = entity.getSname();
        if (sname != null) {
            stmt.bindString(4, sname);
        }
 
        String pic = entity.getPic();
        if (pic != null) {
            stmt.bindString(5, pic);
        }
 
        String bookcount = entity.getBookcount();
        if (bookcount != null) {
            stmt.bindString(6, bookcount);
        }
 
        String description = entity.getDescription();
        if (description != null) {
            stmt.bindString(7, description);
        }
 
        String realcount = entity.getRealcount();
        if (realcount != null) {
            stmt.bindString(8, realcount);
        }
    }

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

    @Override
    public HomeTitle readEntity(Cursor cursor, int offset) {
        HomeTitle entity = new HomeTitle( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // sname
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // pic
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // bookcount
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // description
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // realcount
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, HomeTitle entity, int offset) {
        entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setSname(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPic(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setBookcount(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setDescription(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setRealcount(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(HomeTitle entity, long rowId) {
        entity.set_id(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(HomeTitle entity) {
        if(entity != null) {
            return entity.get_id();
        } else {
            return null;
        }
    }

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

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