package com.cc.infosur.greendao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;


// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table REQUEST.
*/
public class RequestDao extends AbstractDao<Request, Long> {

    public static final String TABLENAME = "REQUEST";

    /**
     * Properties of entity Request.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Request = new Property(1, String.class, "request", false, "REQUEST");
        public final static Property Isrequested = new Property(2, Boolean.class, "isrequested", false, "ISREQUESTED");
        public final static Property Pathimage = new Property(3, String.class, "pathimage", false, "PATHIMAGE");
    };


    public RequestDao(DaoConfig config) {
        super(config);
    }
    
    public RequestDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'REQUEST' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'REQUEST' TEXT," + // 1: request
                "'ISREQUESTED' INTEGER," + // 2: isrequested
                "'PATHIMAGE' TEXT);"); // 3: pathimage
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Request entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String request = entity.getRequest();
        if (request != null) {
            stmt.bindString(2, request);
        }
 
        Boolean isrequested = entity.getIsrequested();
        if (isrequested != null) {
            stmt.bindLong(3, isrequested ? 1l: 0l);
        }
 
        String pathimage = entity.getPathimage();
        if (pathimage != null) {
            stmt.bindString(4, pathimage);
        }
    }

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

    /** @inheritdoc */
    @Override
    public Request readEntity(Cursor cursor, int offset) {
        Request entity = new Request( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // request
            cursor.isNull(offset + 2) ? null : cursor.getShort(offset + 2) != 0, // isrequested
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // pathimage
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Request entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setRequest(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setIsrequested(cursor.isNull(offset + 2) ? null : cursor.getShort(offset + 2) != 0);
        entity.setPathimage(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Request entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Request entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
}
