package hf.lskj.com.carstockcount.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;

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

    public static final String TABLENAME = "USER";

    /**
     * Properties of entity User.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property LoginId = new Property(0, String.class, "loginId", true, "LOGIN_ID");
        public final static Property Password = new Property(1, String.class, "password", false, "PASSWORD");
        public final static Property RealName = new Property(2, String.class, "realName", false, "REAL_NAME");
        public final static Property Role = new Property(3, String.class, "role", false, "ROLE");
        public final static Property StoreName = new Property(4, String.class, "storeName", false, "STORE_NAME");
        public final static Property Current = new Property(5, boolean.class, "current", false, "CURRENT");
    }


    public UserDao(DaoConfig config) {
        super(config);
    }
    
    public UserDao(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\" (" + //
                "\"LOGIN_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: loginId
                "\"PASSWORD\" TEXT," + // 1: password
                "\"REAL_NAME\" TEXT," + // 2: realName
                "\"ROLE\" TEXT," + // 3: role
                "\"STORE_NAME\" TEXT," + // 4: storeName
                "\"CURRENT\" INTEGER NOT NULL );"); // 5: current
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, User entity) {
        stmt.clearBindings();
 
        String loginId = entity.getLoginId();
        if (loginId != null) {
            stmt.bindString(1, loginId);
        }
 
        String password = entity.getPassword();
        if (password != null) {
            stmt.bindString(2, password);
        }
 
        String realName = entity.getRealName();
        if (realName != null) {
            stmt.bindString(3, realName);
        }
 
        String role = entity.getRole();
        if (role != null) {
            stmt.bindString(4, role);
        }
 
        String storeName = entity.getStoreName();
        if (storeName != null) {
            stmt.bindString(5, storeName);
        }
        stmt.bindLong(6, entity.getCurrent() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, User entity) {
        stmt.clearBindings();
 
        String loginId = entity.getLoginId();
        if (loginId != null) {
            stmt.bindString(1, loginId);
        }
 
        String password = entity.getPassword();
        if (password != null) {
            stmt.bindString(2, password);
        }
 
        String realName = entity.getRealName();
        if (realName != null) {
            stmt.bindString(3, realName);
        }
 
        String role = entity.getRole();
        if (role != null) {
            stmt.bindString(4, role);
        }
 
        String storeName = entity.getStoreName();
        if (storeName != null) {
            stmt.bindString(5, storeName);
        }
        stmt.bindLong(6, entity.getCurrent() ? 1L: 0L);
    }

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

    @Override
    public User readEntity(Cursor cursor, int offset) {
        User entity = new User( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // loginId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // password
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // realName
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // role
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // storeName
            cursor.getShort(offset + 5) != 0 // current
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, User entity, int offset) {
        entity.setLoginId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setPassword(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setRealName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setRole(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setStoreName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setCurrent(cursor.getShort(offset + 5) != 0);
     }
    
    @Override
    protected final String updateKeyAfterInsert(User entity, long rowId) {
        return entity.getLoginId();
    }
    
    @Override
    public String getKey(User entity) {
        if(entity != null) {
            return entity.getLoginId();
        } else {
            return null;
        }
    }

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

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