package com.zhangke.shizhong.db;

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 "APPLICATION_INFO".
*/
public class ApplicationInfoDao extends AbstractDao<ApplicationInfo, String> {

    public static final String TABLENAME = "APPLICATION_INFO";

    /**
     * Properties of entity ApplicationInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property AppName = new Property(0, String.class, "appName", false, "APP_NAME");
        public final static Property PackageName = new Property(1, String.class, "packageName", true, "PACKAGE_NAME");
        public final static Property VersionName = new Property(2, String.class, "versionName", false, "VERSION_NAME");
        public final static Property VersionCode = new Property(3, int.class, "versionCode", false, "VERSION_CODE");
        public final static Property SortTarget = new Property(4, String.class, "sortTarget", false, "SORT_TARGET");
        public final static Property IsSystemApp = new Property(5, boolean.class, "isSystemApp", false, "IS_SYSTEM_APP");
    }


    public ApplicationInfoDao(DaoConfig config) {
        super(config);
    }
    
    public ApplicationInfoDao(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 + "\"APPLICATION_INFO\" (" + //
                "\"APP_NAME\" TEXT," + // 0: appName
                "\"PACKAGE_NAME\" TEXT PRIMARY KEY NOT NULL ," + // 1: packageName
                "\"VERSION_NAME\" TEXT," + // 2: versionName
                "\"VERSION_CODE\" INTEGER NOT NULL ," + // 3: versionCode
                "\"SORT_TARGET\" TEXT," + // 4: sortTarget
                "\"IS_SYSTEM_APP\" INTEGER NOT NULL );"); // 5: isSystemApp
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, ApplicationInfo entity) {
        stmt.clearBindings();
 
        String appName = entity.getAppName();
        if (appName != null) {
            stmt.bindString(1, appName);
        }
 
        String packageName = entity.getPackageName();
        if (packageName != null) {
            stmt.bindString(2, packageName);
        }
 
        String versionName = entity.getVersionName();
        if (versionName != null) {
            stmt.bindString(3, versionName);
        }
        stmt.bindLong(4, entity.getVersionCode());
 
        String sortTarget = entity.getSortTarget();
        if (sortTarget != null) {
            stmt.bindString(5, sortTarget);
        }
        stmt.bindLong(6, entity.getIsSystemApp() ? 1L: 0L);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ApplicationInfo entity) {
        stmt.clearBindings();
 
        String appName = entity.getAppName();
        if (appName != null) {
            stmt.bindString(1, appName);
        }
 
        String packageName = entity.getPackageName();
        if (packageName != null) {
            stmt.bindString(2, packageName);
        }
 
        String versionName = entity.getVersionName();
        if (versionName != null) {
            stmt.bindString(3, versionName);
        }
        stmt.bindLong(4, entity.getVersionCode());
 
        String sortTarget = entity.getSortTarget();
        if (sortTarget != null) {
            stmt.bindString(5, sortTarget);
        }
        stmt.bindLong(6, entity.getIsSystemApp() ? 1L: 0L);
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
    }    

    @Override
    public ApplicationInfo readEntity(Cursor cursor, int offset) {
        ApplicationInfo entity = new ApplicationInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // appName
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // packageName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // versionName
            cursor.getInt(offset + 3), // versionCode
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // sortTarget
            cursor.getShort(offset + 5) != 0 // isSystemApp
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ApplicationInfo entity, int offset) {
        entity.setAppName(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setPackageName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setVersionName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setVersionCode(cursor.getInt(offset + 3));
        entity.setSortTarget(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setIsSystemApp(cursor.getShort(offset + 5) != 0);
     }
    
    @Override
    protected final String updateKeyAfterInsert(ApplicationInfo entity, long rowId) {
        return entity.getPackageName();
    }
    
    @Override
    public String getKey(ApplicationInfo entity) {
        if(entity != null) {
            return entity.getPackageName();
        } else {
            return null;
        }
    }

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

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