package com.tofly.data.sql.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;

import com.tofly.ghrq_route.module.user.domain.DepartUserListBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DEPART_USER_LIST_BEANS".
*/
public class DepartUserListBeansDao extends AbstractDao<DepartUserListBean, String> {

    public static final String TABLENAME = "DEPART_USER_LIST_BEANS";

    /**
     * Properties of entity DepartUserListBeans.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property RealName = new Property(1, String.class, "realName", false, "REAL_NAME");
        public final static Property DepartmentId = new Property(2, String.class, "departmentId", false, "DEPARTMENT_ID");
    }


    public DepartUserListBeansDao(DaoConfig config) {
        super(config);
    }
    
    public DepartUserListBeansDao(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 + "\"DEPART_USER_LIST_BEANS\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"REAL_NAME\" TEXT," + // 1: realName
                "\"DEPARTMENT_ID\" TEXT);"); // 2: departmentId
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, DepartUserListBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String realName = entity.getRealName();
        if (realName != null) {
            stmt.bindString(2, realName);
        }
 
        String departmentId = entity.getDepartmentId();
        if (departmentId != null) {
            stmt.bindString(3, departmentId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, DepartUserListBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String realName = entity.getRealName();
        if (realName != null) {
            stmt.bindString(2, realName);
        }
 
        String departmentId = entity.getDepartmentId();
        if (departmentId != null) {
            stmt.bindString(3, departmentId);
        }
    }

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

    @Override
    public DepartUserListBean readEntity(Cursor cursor, int offset) {
        DepartUserListBean entity = new DepartUserListBean( //
            cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // realName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // departmentId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, DepartUserListBean entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setRealName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setDepartmentId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final String updateKeyAfterInsert(DepartUserListBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(DepartUserListBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(DepartUserListBean entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

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