package com.gingersoft.gsa.cloud.database.greendao;

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.gingersoft.gsa.cloud.database.bean.Function;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "FUNCTION".
*/
public class FunctionDao extends AbstractDao<Function, Long> {

    public static final String TABLENAME = "FUNCTION";

    /**
     * Properties of entity Function.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Dbid = new Property(0, Long.class, "dbid", true, "_id");
        public final static Property Id = new Property(1, Long.class, "id", false, "ID");
        public final static Property ParentId = new Property(2, int.class, "parentId", false, "PARENT_ID");
        public final static Property GroupId = new Property(3, int.class, "groupId", false, "GROUP_ID");
        public final static Property Status = new Property(4, int.class, "status", false, "STATUS");
        public final static Property EffectiveTime = new Property(5, long.class, "effectiveTime", false, "EFFECTIVE_TIME");
        public final static Property ResName = new Property(6, String.class, "resName", false, "RES_NAME");
        public final static Property ResUrl = new Property(7, String.class, "resUrl", false, "RES_URL");
        public final static Property ImageURL = new Property(8, String.class, "imageURL", false, "IMAGE_URL");
        public final static Property IcRes = new Property(9, int.class, "icRes", false, "IC_RES");
    }


    public FunctionDao(DaoConfig config) {
        super(config);
    }
    
    public FunctionDao(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 + "\"FUNCTION\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: dbid
                "\"ID\" INTEGER NOT NULL ," + // 1: id
                "\"PARENT_ID\" INTEGER NOT NULL ," + // 2: parentId
                "\"GROUP_ID\" INTEGER NOT NULL ," + // 3: groupId
                "\"STATUS\" INTEGER NOT NULL ," + // 4: status
                "\"EFFECTIVE_TIME\" INTEGER NOT NULL ," + // 5: effectiveTime
                "\"RES_NAME\" TEXT," + // 6: resName
                "\"RES_URL\" TEXT," + // 7: resUrl
                "\"IMAGE_URL\" TEXT," + // 8: imageURL
                "\"IC_RES\" INTEGER NOT NULL );"); // 9: icRes
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, Function entity) {
        stmt.clearBindings();
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(1, dbid);
        }
        stmt.bindLong(2, entity.getId());
        stmt.bindLong(3, entity.getParentId());
        stmt.bindLong(4, entity.getGroupId());
        stmt.bindLong(5, entity.getStatus());
        stmt.bindLong(6, entity.getEffectiveTime());
 
        String resName = entity.getResName();
        if (resName != null) {
            stmt.bindString(7, resName);
        }
 
        String resUrl = entity.getResUrl();
        if (resUrl != null) {
            stmt.bindString(8, resUrl);
        }
 
        String imageURL = entity.getImageURL();
        if (imageURL != null) {
            stmt.bindString(9, imageURL);
        }
        stmt.bindLong(10, entity.getIcRes());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Function entity) {
        stmt.clearBindings();
 
        Long dbid = entity.getDbid();
        if (dbid != null) {
            stmt.bindLong(1, dbid);
        }
        stmt.bindLong(2, entity.getId());
        stmt.bindLong(3, entity.getParentId());
        stmt.bindLong(4, entity.getGroupId());
        stmt.bindLong(5, entity.getStatus());
        stmt.bindLong(6, entity.getEffectiveTime());
 
        String resName = entity.getResName();
        if (resName != null) {
            stmt.bindString(7, resName);
        }
 
        String resUrl = entity.getResUrl();
        if (resUrl != null) {
            stmt.bindString(8, resUrl);
        }
 
        String imageURL = entity.getImageURL();
        if (imageURL != null) {
            stmt.bindString(9, imageURL);
        }
        stmt.bindLong(10, entity.getIcRes());
    }

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

    @Override
    public Function readEntity(Cursor cursor, int offset) {
        Function entity = new Function( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // dbid
            cursor.getLong(offset + 1), // id
            cursor.getInt(offset + 2), // parentId
            cursor.getInt(offset + 3), // groupId
            cursor.getInt(offset + 4), // status
            cursor.getLong(offset + 5), // effectiveTime
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // resName
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // resUrl
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // imageURL
            cursor.getInt(offset + 9) // icRes
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Function entity, int offset) {
        entity.setDbid(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.getLong(offset + 1));
        entity.setParentId(cursor.getInt(offset + 2));
        entity.setGroupId(cursor.getInt(offset + 3));
        entity.setStatus(cursor.getInt(offset + 4));
        entity.setEffectiveTime(cursor.getLong(offset + 5));
        entity.setResName(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setResUrl(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setImageURL(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setIcRes(cursor.getInt(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Function entity, long rowId) {
        entity.setDbid(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Function entity) {
        if(entity != null) {
            return entity.getDbid();
        } else {
            return null;
        }
    }

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

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