package com.littleinc.orm_benchmark.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;

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

    public static final String TABLENAME = "MESSAGE";

    /**
     * Properties of entity Message.<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 Content = new Property(1, String.class, "content", false, "CONTENT");
        public final static Property Client_id = new Property(2, long.class, "client_id", false, "CLIENT_ID");
        public final static Property Created_at = new Property(3, int.class, "created_at", false, "CREATED_AT");
        public final static Property Sorted_by = new Property(4, double.class, "sorted_by", false, "SORTED_BY");
        public final static Property Command_id = new Property(5, long.class, "command_id", false, "COMMAND_ID");
        public final static Property Sender_id = new Property(6, long.class, "sender_id", false, "SENDER_ID");
        public final static Property Channel_id = new Property(7, long.class, "channel_id", false, "CHANNEL_ID");
    }

    private DaoSession daoSession;


    public MessageDao(DaoConfig config) {
        super(config);
    }
    
    public MessageDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = 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 + "\"MESSAGE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"CONTENT\" TEXT," + // 1: content
                "\"CLIENT_ID\" INTEGER NOT NULL ," + // 2: client_id
                "\"CREATED_AT\" INTEGER NOT NULL ," + // 3: created_at
                "\"SORTED_BY\" REAL NOT NULL ," + // 4: sorted_by
                "\"COMMAND_ID\" INTEGER NOT NULL ," + // 5: command_id
                "\"SENDER_ID\" INTEGER NOT NULL ," + // 6: sender_id
                "\"CHANNEL_ID\" INTEGER NOT NULL );"); // 7: channel_id
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_MESSAGE_COMMAND_ID ON \"MESSAGE\"" +
                " (\"COMMAND_ID\");");
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, Message entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(2, content);
        }
        stmt.bindLong(3, entity.getClient_id());
        stmt.bindLong(4, entity.getCreated_at());
        stmt.bindDouble(5, entity.getSorted_by());
        stmt.bindLong(6, entity.getCommand_id());
        stmt.bindLong(7, entity.getSender_id());
        stmt.bindLong(8, entity.getChannel_id());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Message entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(2, content);
        }
        stmt.bindLong(3, entity.getClient_id());
        stmt.bindLong(4, entity.getCreated_at());
        stmt.bindDouble(5, entity.getSorted_by());
        stmt.bindLong(6, entity.getCommand_id());
        stmt.bindLong(7, entity.getSender_id());
        stmt.bindLong(8, entity.getChannel_id());
    }

    @Override
    protected final void attachEntity(Message entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

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

    @Override
    public Message readEntity(Cursor cursor, int offset) {
        Message entity = new Message( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // content
            cursor.getLong(offset + 2), // client_id
            cursor.getInt(offset + 3), // created_at
            cursor.getDouble(offset + 4), // sorted_by
            cursor.getLong(offset + 5), // command_id
            cursor.getLong(offset + 6), // sender_id
            cursor.getLong(offset + 7) // channel_id
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Message entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setContent(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setClient_id(cursor.getLong(offset + 2));
        entity.setCreated_at(cursor.getInt(offset + 3));
        entity.setSorted_by(cursor.getDouble(offset + 4));
        entity.setCommand_id(cursor.getLong(offset + 5));
        entity.setSender_id(cursor.getLong(offset + 6));
        entity.setChannel_id(cursor.getLong(offset + 7));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Message entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Message entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

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