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.buildManage.domain.UserListBean;

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

    public static final String TABLENAME = "USER_LIST_BEAN";

    /**
     * Properties of entity UserListBean.<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 DepartmentId = new Property(1, String.class, "departmentId", false, "DEPARTMENT_ID");
        public final static Property Username = new Property(2, String.class, "username", false, "USERNAME");
        public final static Property RealName = new Property(3, String.class, "realName", false, "REAL_NAME");
    }


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

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

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

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

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

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

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

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