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 EffectiveTime = new Property(4, long.class, "effectiveTime", false, "EFFECTIVE_TIME");
        public final static Property ResName = new Property(5, String.class, "resName", false, "RES_NAME");
        public final static Property ResUrl = new Property(6, String.class, "resUrl", false, "RES_URL");
        public final static Property ImageURL = new Property(7, String.class, "imageURL", false, "IMAGE_URL");
        public final static Property IcRes = new Property(8, int.class, "icRes", false, "IC_RES");
        public final static Property Status = new Property(9, int.class, "status", false, "STATUS");
    }


    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
                "\"EFFECTIVE_TIME\" INTEGER NOT NULL ," + // 4: effectiveTime
                "\"RES_NAME\" TEXT," + // 5: resName
                "\"RES_URL\" TEXT," + // 6: resUrl
                "\"IMAGE_URL\" TEXT," + // 7: imageURL
                "\"IC_RES\" INTEGER NOT NULL ," + // 8: icRes
                "\"STATUS\" INTEGER NOT NULL );"); // 9: status
    }

    /** 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.getEffectiveTime());
 
        String resName = entity.getResName();
        if (resName != null) {
            stmt.bindString(6, resName);
        }
 
        String resUrl = entity.getResUrl();
        if (resUrl != null) {
            stmt.bindString(7, resUrl);
        }
 
        String imageURL = entity.getImageURL();
        if (imageURL != null) {
            stmt.bindString(8, imageURL);
        }
        stmt.bindLong(9, entity.getIcRes());
        stmt.bindLong(10, entity.getStatus());
    }

    @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.getEffectiveTime());
 
        String resName = entity.getResName();
        if (resName != null) {
            stmt.bindString(6, resName);
        }
 
        String resUrl = entity.getResUrl();
        if (resUrl != null) {
            stmt.bindString(7, resUrl);
        }
 
        String imageURL = entity.getImageURL();
        if (imageURL != null) {
            stmt.bindString(8, imageURL);
        }
        stmt.bindLong(9, entity.getIcRes());
        stmt.bindLong(10, entity.getStatus());
    }

    @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.getLong(offset + 4), // effectiveTime
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // resName
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // resUrl
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // imageURL
            cursor.getInt(offset + 8), // icRes
            cursor.getInt(offset + 9) // status
        );
        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.setEffectiveTime(cursor.getLong(offset + 4));
        entity.setResName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setResUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setImageURL(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setIcRes(cursor.getInt(offset + 8));
        entity.setStatus(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;
    }
    
}
