package com.adins.mss.dao;

import android.database.Cursor;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.database.Database;
import de.greenrobot.dao.database.DatabaseStatement;

import com.adins.mss.dao.Theme;

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

    public static final String TABLENAME = "TR_THEME";

    /**
     * Properties of entity Theme.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Uuid_theme = new Property(0, String.class, "uuid_theme", true, "UUID_THEME");
        public final static Property Application_type = new Property(1, String.class, "application_type", false, "APPLICATION_TYPE");
        public final static Property Version = new Property(2, String.class, "version", false, "VERSION");
    };

    private DaoSession daoSession;


    public ThemeDao(DaoConfig config) {
        super(config);
    }
    
    public ThemeDao(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 + "\"TR_THEME\" (" + //
                "\"UUID_THEME\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid_theme
                "\"APPLICATION_TYPE\" TEXT NOT NULL ," + // 1: application_type
                "\"VERSION\" TEXT);"); // 2: version
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(DatabaseStatement stmt, Theme entity) {
        stmt.clearBindings();
        stmt.bindString(1, entity.getUuid_theme());
        stmt.bindString(2, entity.getApplication_type());
 
        String version = entity.getVersion();
        if (version != null) {
            stmt.bindString(3, version);
        }
    }

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

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

    /** @inheritdoc */
    @Override
    public Theme readEntity(Cursor cursor, int offset) {
        Theme entity = new Theme( //
            cursor.getString(offset + 0), // uuid_theme
            cursor.getString(offset + 1), // application_type
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // version
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Theme entity, int offset) {
        entity.setUuid_theme(cursor.getString(offset + 0));
        entity.setApplication_type(cursor.getString(offset + 1));
        entity.setVersion(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    /** @inheritdoc */
    @Override
    protected String updateKeyAfterInsert(Theme entity, long rowId) {
        return entity.getUuid_theme();
    }
    
    /** @inheritdoc */
    @Override
    public String getKey(Theme entity) {
        if(entity != null) {
            return entity.getUuid_theme();
        } else {
            return null;
        }
    }

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