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.UserMenuBean;

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

    public static final String TABLENAME = "DB_USER_MENU";

    /**
     * Properties of entity UserMenuBean.<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 Code = new Property(1, String.class, "code", false, "CODE");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Icon = new Property(3, String.class, "icon", false, "ICON");
        public final static Property Sort = new Property(4, int.class, "sort", false, "SORT");
        public final static Property Type = new Property(5, String.class, "type", false, "TYPE");
        public final static Property ParentId = new Property(6, String.class, "parentId", false, "PARENT_ID");
        public final static Property Userid = new Property(7, String.class, "userid", false, "USERID");
    }


    public UserMenuBeanDao(DaoConfig config) {
        super(config);
    }
    
    public UserMenuBeanDao(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 + "\"DB_USER_MENU\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL UNIQUE ," + // 0: id
                "\"CODE\" TEXT," + // 1: code
                "\"NAME\" TEXT," + // 2: name
                "\"ICON\" TEXT," + // 3: icon
                "\"SORT\" INTEGER NOT NULL ," + // 4: sort
                "\"TYPE\" TEXT," + // 5: type
                "\"PARENT_ID\" TEXT," + // 6: parentId
                "\"USERID\" TEXT);"); // 7: userid
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, UserMenuBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(2, code);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String icon = entity.getIcon();
        if (icon != null) {
            stmt.bindString(4, icon);
        }
        stmt.bindLong(5, entity.getSort());
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(6, type);
        }
 
        String parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindString(7, parentId);
        }
 
        String userid = entity.getUserid();
        if (userid != null) {
            stmt.bindString(8, userid);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, UserMenuBean entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getId());
 
        String code = entity.getCode();
        if (code != null) {
            stmt.bindString(2, code);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String icon = entity.getIcon();
        if (icon != null) {
            stmt.bindString(4, icon);
        }
        stmt.bindLong(5, entity.getSort());
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(6, type);
        }
 
        String parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindString(7, parentId);
        }
 
        String userid = entity.getUserid();
        if (userid != null) {
            stmt.bindString(8, userid);
        }
    }

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

    @Override
    public UserMenuBean readEntity(Cursor cursor, int offset) {
        UserMenuBean entity = new UserMenuBean( //
            cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // code
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // icon
            cursor.getInt(offset + 4), // sort
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // type
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // parentId
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // userid
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, UserMenuBean entity, int offset) {
        entity.setId(cursor.getString(offset + 0));
        entity.setCode(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setIcon(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setSort(cursor.getInt(offset + 4));
        entity.setType(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setParentId(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setUserid(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
     }
    
    @Override
    protected final String updateKeyAfterInsert(UserMenuBean entity, long rowId) {
        return entity.getId();
    }
    
    @Override
    public String getKey(UserMenuBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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