package com.tofly.data.sql.dao;

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.tofly.ghrq_route.module.plan.domain.OfflinePointLineBean;

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

    public static final String TABLENAME = "DB_OFFLINE_POINTLINE";

    /**
     * Properties of entity OfflinePointLineBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Temp_id = new Property(0, String.class, "temp_id", true, "TEMP_ID");
        public final static Property Plan_id = new Property(1, String.class, "plan_id", false, "PLAN_ID");
        public final static Property Isover = new Property(2, int.class, "isover", false, "ISOVER");
        public final static Property Isupload = new Property(3, int.class, "isupload", false, "ISUPLOAD");
        public final static Property Ispast = new Property(4, int.class, "ispast", false, "ISPAST");
        public final static Property Lat = new Property(5, double.class, "lat", false, "LAT");
        public final static Property Lng = new Property(6, double.class, "lng", false, "LNG");
        public final static Property Geometry = new Property(7, String.class, "geometry", false, "GEOMETRY");
    }

    private DaoSession daoSession;


    public OfflinePointLineBeanDao(DaoConfig config) {
        super(config);
    }
    
    public OfflinePointLineBeanDao(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 + "\"DB_OFFLINE_POINTLINE\" (" + //
                "\"TEMP_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: temp_id
                "\"PLAN_ID\" TEXT," + // 1: plan_id
                "\"ISOVER\" INTEGER NOT NULL ," + // 2: isover
                "\"ISUPLOAD\" INTEGER NOT NULL ," + // 3: isupload
                "\"ISPAST\" INTEGER NOT NULL ," + // 4: ispast
                "\"LAT\" REAL NOT NULL ," + // 5: lat
                "\"LNG\" REAL NOT NULL ," + // 6: lng
                "\"GEOMETRY\" TEXT);"); // 7: geometry
    }

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

    @Override
    protected final void bindValues(DatabaseStatement stmt, OfflinePointLineBean entity) {
        stmt.clearBindings();
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(1, temp_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(2, plan_id);
        }
        stmt.bindLong(3, entity.getIsover());
        stmt.bindLong(4, entity.getIsupload());
        stmt.bindLong(5, entity.getIspast());
        stmt.bindDouble(6, entity.getLat());
        stmt.bindDouble(7, entity.getLng());
 
        String geometry = entity.getGeometry();
        if (geometry != null) {
            stmt.bindString(8, geometry);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, OfflinePointLineBean entity) {
        stmt.clearBindings();
 
        String temp_id = entity.getTemp_id();
        if (temp_id != null) {
            stmt.bindString(1, temp_id);
        }
 
        String plan_id = entity.getPlan_id();
        if (plan_id != null) {
            stmt.bindString(2, plan_id);
        }
        stmt.bindLong(3, entity.getIsover());
        stmt.bindLong(4, entity.getIsupload());
        stmt.bindLong(5, entity.getIspast());
        stmt.bindDouble(6, entity.getLat());
        stmt.bindDouble(7, entity.getLng());
 
        String geometry = entity.getGeometry();
        if (geometry != null) {
            stmt.bindString(8, geometry);
        }
    }

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

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

    @Override
    public OfflinePointLineBean readEntity(Cursor cursor, int offset) {
        OfflinePointLineBean entity = new OfflinePointLineBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // temp_id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // plan_id
            cursor.getInt(offset + 2), // isover
            cursor.getInt(offset + 3), // isupload
            cursor.getInt(offset + 4), // ispast
            cursor.getDouble(offset + 5), // lat
            cursor.getDouble(offset + 6), // lng
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // geometry
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, OfflinePointLineBean entity, int offset) {
        entity.setTemp_id(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setPlan_id(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setIsover(cursor.getInt(offset + 2));
        entity.setIsupload(cursor.getInt(offset + 3));
        entity.setIspast(cursor.getInt(offset + 4));
        entity.setLat(cursor.getDouble(offset + 5));
        entity.setLng(cursor.getDouble(offset + 6));
        entity.setGeometry(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
     }
    
    @Override
    protected final String updateKeyAfterInsert(OfflinePointLineBean entity, long rowId) {
        return entity.getTemp_id();
    }
    
    @Override
    public String getKey(OfflinePointLineBean entity) {
        if(entity != null) {
            return entity.getTemp_id();
        } else {
            return null;
        }
    }

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

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