package com.phlx.anchorcollect_p.db.gen;

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.phlx.anchorcollect_p.entity.AncestryinfoEntity;

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

    public static final String TABLENAME = "ANCESTRYINFO_ENTITY";

    /**
     * Properties of entity AncestryinfoEntity.<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 Ancestryid = new Property(1, String.class, "ancestryid", false, "ANCESTRYID");
        public final static Property Ancestryname = new Property(2, String.class, "ancestryname", false, "ANCESTRYNAME");
        public final static Property Remark = new Property(3, String.class, "remark", false, "REMARK");
        public final static Property Timestamp = new Property(4, long.class, "timestamp", false, "TIMESTAMP");
    }


    public AncestryinfoEntityDao(DaoConfig config) {
        super(config);
    }
    
    public AncestryinfoEntityDao(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 + "\"ANCESTRYINFO_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"ANCESTRYID\" TEXT," + // 1: ancestryid
                "\"ANCESTRYNAME\" TEXT," + // 2: ancestryname
                "\"REMARK\" TEXT," + // 3: remark
                "\"TIMESTAMP\" INTEGER NOT NULL );"); // 4: timestamp
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "ancestryTime ON \"ANCESTRYINFO_ENTITY\"" +
                " (\"TIMESTAMP\" ASC);");
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, AncestryinfoEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String ancestryid = entity.getAncestryid();
        if (ancestryid != null) {
            stmt.bindString(2, ancestryid);
        }
 
        String ancestryname = entity.getAncestryname();
        if (ancestryname != null) {
            stmt.bindString(3, ancestryname);
        }
 
        String remark = entity.getRemark();
        if (remark != null) {
            stmt.bindString(4, remark);
        }
        stmt.bindLong(5, entity.getTimestamp());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AncestryinfoEntity entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String ancestryid = entity.getAncestryid();
        if (ancestryid != null) {
            stmt.bindString(2, ancestryid);
        }
 
        String ancestryname = entity.getAncestryname();
        if (ancestryname != null) {
            stmt.bindString(3, ancestryname);
        }
 
        String remark = entity.getRemark();
        if (remark != null) {
            stmt.bindString(4, remark);
        }
        stmt.bindLong(5, entity.getTimestamp());
    }

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

    @Override
    public AncestryinfoEntity readEntity(Cursor cursor, int offset) {
        AncestryinfoEntity entity = new AncestryinfoEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // ancestryid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // ancestryname
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // remark
            cursor.getLong(offset + 4) // timestamp
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AncestryinfoEntity entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setAncestryid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setAncestryname(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setRemark(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setTimestamp(cursor.getLong(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AncestryinfoEntity entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AncestryinfoEntity entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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