package com.sunzee.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import com.sunzee.model.domain.WarringBean;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.internal.DaoConfig;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * DAO for table "WARRING_BEAN".
*/
public class WarringBeanDao extends AbstractDao<WarringBean, Long> {

    public static final String TABLENAME = "WARRING_BEAN";

    /**
     * Properties of entity WarringBean.<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 Time = new Property(1, long.class, "time", false, "TIME");
        public final static Property ThingError = new Property(2, String.class, "thingError", false, "ERROR");
        public final static Property Remark = new Property(3, String.class, "remark", false, "REMARK");
    }


    public WarringBeanDao(DaoConfig config) {
        super(config);
    }
    
    public WarringBeanDao(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 + "\"WARRING_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"TIME\" INTEGER NOT NULL ," + // 1: time
                "\"ERROR\" TEXT," + // 2: thingError
                "\"REMARK\" TEXT);"); // 3: remark
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, WarringBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getTime());
 
        String thingError = entity.getThingError();
        if (thingError != null) {
            stmt.bindString(3, thingError);
        }
 
        String remark = entity.getRemark();
        if (remark != null) {
            stmt.bindString(4, remark);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WarringBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getTime());
 
        String thingError = entity.getThingError();
        if (thingError != null) {
            stmt.bindString(3, thingError);
        }
 
        String remark = entity.getRemark();
        if (remark != null) {
            stmt.bindString(4, remark);
        }
    }

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

    @Override
    public WarringBean readEntity(Cursor cursor, int offset) {
        WarringBean entity = new WarringBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getLong(offset + 1), // time
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // thingError
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // remark
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WarringBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setTime(cursor.getLong(offset + 1));
        entity.setThingError(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setRemark(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(WarringBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(WarringBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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